次の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);
}
}
}
}
だから私の質問は、次のようにする方法です: スピナーから項目を選択 -> 選択した基準でリストをフィルター/並べ替え 基準は解析されますが、リストには表示されないため、データはそこにありますが、どのように行うのですか?