0

我有一个来自 json 的列表视图,如下所示:

{
"GetPOIByTypeResult": [
    {
        "ID": 1,
        "Name": "Spitalul Judetean",
        "Phone": "085228291",
        "Rating": 44,
        "Schedule": {
            "ClosingHour": 16,
            "ID": 1,
            "IsNonStop": false,
            "IsOpenOnFriday": true,
            "IsOpenOnMonday": true,
            "IsOpenOnSaturday": false,
            "IsOpenOnSunday": false,
            "IsOpenOnThursday": true,
            "IsOpenOnTuesday": true,
            "IsOpenOnWednesday": true,
            "Name": "Monday to Friday",
            "OpenHour": 8
        },
        "Specialities": [
            {
                "ID": 1,
                "Name": "Stomatologie"
            },
            {
                "ID": 2,
                "Name": "Radiologie"
            },
            {
                "ID": 3,
                "Name": "Cardiologie"
            },
            {
                "ID": 4,
                "Name": "Ginecologie"
            },
            {
                "ID": 5,
                "Name": "Pediatrie"
            },
            {
                "ID": 6,
                "Name": "Patologie"
            },
            {
                "ID": 7,
                "Name": "Oncologie"
            },
            {
                "ID": 8,
                "Name": "Macelarie"
            },
            {
                "ID": 9,
                "Name": "Oftalmologie"
            },
            {
                "ID": 10,
                "Name": "Ghipsologie"
            }
        ],
        "Type": "Hospital"
    },

]
}

在我的列表视图中,有来自字段的结果:“名称”。我想按列表中未显示的专业过滤我的列表,只返回值。我实际上不知道如何使这项工作,这是我到目前为止所做的:

package com.example.medical.map;

import java.util.ArrayList;

public class SearchActivityHospitals extends ListActivity {

Button searchButton;
Button closeButton;
public Spinner spinner1;
private String poiType[];
private boolean isSearch = false;
EditText editText, editText2;
JsonArrayAdapterHospitals adapter;
ArrayList<Hospitals> tempName = new ArrayList<Hospitals>();

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_activity_layout_actionbar_hospitals);
    adapter = new JsonArrayAdapterHospitals(this, tempName);
    setListAdapter(adapter);

    poiType = new String[] {"", "Stomatologie", "Radiologie", "Cardiologie", "Ginecologie", "Pediatrie", "Patologie", "Oncologie", "Macelarie", "Oftalmologie", "Ghipsologie"};
    //this is my spinner
    ArrayAdapter<String> adapter0 = new ArrayAdapter<String>(SearchActivityHospitals.this, android.R.layout.simple_spinner_item, poiType);
    adapter0.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    spinner1.findViewById(R.id.spinnerSpecialityHospitals);
    spinner1.setAdapter(adapter0);
    spinner1.setOnItemSelectedListener(new MyOnItemSelectedListener()
    );

    WebService.setOnFinishAllHospitals(new OnFinishAllHospitals() {

        public void onFinishAllHospitals(ArrayList<Hospitals> hospitals) {

            if (hospitals != null) {
                if (hospitals.size() > 0) {
                    tempName.clear();
                    tempName.addAll(hospitals);
                    adapter.notifyDataSetChanged();
                }

            }

        }

    });

    WebService
            .GetPOIByType("http://82.77.55.81:9090/MedicalMap/MedicalMap.svc/Getpoibytype/hospital");

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            Intent intent = new Intent(SearchActivityHospitals.this, DetailsHospitals.class);
            intent.putExtra("Value", tempName.get(position));
            startActivity(intent);

        }
    });

    editText = (EditText) findViewById(R.id.editNameTextHospitals);
    editText.addTextChangedListener(new TextWatcher() {

        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            adapter.getFilter().filter(s); // Filter from my adapter
            adapter.notifyDataSetChanged(); // Update my view
        }

        public void afterTextChanged(Editable s) {

        }

    });

    editText2 = (EditText) findViewById(R.id.editAddressTextHospitals);
    editText2.addTextChangedListener(new TextWatcher() {

        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            adapter.getFilter().filter(s); // Filter from my adapter
            adapter.notifyDataSetChanged(); // Update my view
        }

        public void afterTextChanged(Editable s) {

        }

    });



}
//and here is my onitem click listener which I have no idea how to do, please help
public class MyOnItemSelectedListener implements OnItemSelectedListener{

    public void onItemSelected(AdapterView<?> parent, View v, int position,
            long id) {
        if(spinner1.getSelectedItem().equals("Stomatologie")){

        }else{

        }
        if(spinner1.getSelectedItem().equals("Radiologie")){

        }else{

        }
        if(spinner1.getSelectedItem().equals("Cardiologie")){

        }else{

        }
        if(spinner1.getSelectedItem().equals("Ginecologie")){

        }else{

        }
        if(spinner1.getSelectedItem().equals("Pediatrie")){

        }else{

        }
        if(spinner1.getSelectedItem().equals("Patologie")){

        }else{

        }
        if(spinner1.getSelectedItem().equals("Oncologie")){

        }else{

        }
        if(spinner1.getSelectedItem().equals("Macelarie")){

        }else{

        }
        if(spinner1.getSelectedItem().equals("Oftalmologie")){

        }else{

        }
        if(spinner1.getSelectedItem().equals("Ghipsologie")){

        }else{

        }

    }


    public void onNothingSelected(AdapterView<?> arg0) {
        spinner1.getSelectedItem().equals("");
        {

        }
    }



public void handleClick_search(View v) {

    ImageView searchButton = (ImageView) findViewById(R.id.searchButton);
    searchButton.setVisibility(View.INVISIBLE);
    LinearLayout layout = (LinearLayout) findViewById(R.id.searchFieldLayout);
    layout.setVisibility(View.VISIBLE);

}

public void handleClick_closeSearch(View v) {

    ImageView searchButton = (ImageView) findViewById(R.id.searchButton);
    searchButton.setVisibility(View.VISIBLE);
    LinearLayout layout = (LinearLayout) findViewById(R.id.searchFieldLayout);
    layout.setVisibility(View.GONE);

}

public void showSearch() {

    if (isSearch != true) {
        isSearch = true;
        searchButton.setVisibility(View.INVISIBLE);
        closeButton.setVisibility(View.VISIBLE);
        findViewById(R.layout.search_activity_layout_doctors).setVisibility(View.VISIBLE);

    }

}

public void hideSearch() {
    if (isSearch != false) {
        isSearch = false;
        searchButton.setVisibility(View.VISIBLE);
        closeButton.setVisibility(View.GONE);
        findViewById(R.layout.search_activity_layout_doctors).setVisibility(View.GONE);

    }

}


}
}

所以我的问题是,如何进行以下操作: 从微调器中选择项目-> 按选定条件过滤/排序列表 标准已解析但未显示在列表中,因此数据存在但如何操作?

4

1 回答 1

1

我想你可以做的是:

  1. 微调器中项目的 OnSelect,调用一些函数 reorganizeList(String criteria)
  2. 在 reorganizeList(criteria) 中:假设你的数据集是一个 List,mListData。对数据使用 Collections.sort() 并使用标准对数据进行排序。
  3. 在适配器上调用 notifyDataSetChanged()。
于 2012-07-25T11:33:13.457 回答