0
検索可能なスピナーを作成して、それに配列アダプターを接続しようとしています。スピナーの内容はオブジェクトでなければなりません(私はIDを取得して名前を表示できるようにこれを行いました)。私はほぼ完了ですが、代わりに表示されたばかりの名前で、私はこれを取得: searchable spinner検索可能なスピナーの項目のテキストを変更する方法
ここに私のコードです:
public class CitySpinnerAdapter extends ArrayAdapter<City> {
private Context context;
private ArrayList<City> myObjs;
public CitySpinnerAdapter(Context context, int textViewResourceId,
ArrayList<City> myObjs) {
super(context, textViewResourceId, myObjs);
this.context = context;
this.myObjs = myObjs;
}
public int getCount(){
return myObjs.size();
}
public City getItem(int position){
return myObjs.get(position);
}
public long getItemId(int position){
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView label = new TextView(context);
label.setText(myObjs.get(position).getName());
return label;
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
TextView label = new TextView(context);
label.setText(myObjs.get(position).getName());
return label;
}}
、ここでは、私は私のスピナーを作成方法は次のとおりです。
city2Spinner = (SearchableSpinner) findViewById(R.id.city2);
CityDBHelper citydb = new CityDBHelper(getApplicationContext());
ArrayList<HashMap<String, String>> cities2 = citydb.getCities();
cities2Obj = new ArrayList<City>();
for(HashMap<String, String> city2 : cities2){
//for(String key : province.keySet()){
//String name = province.get(key);
cities2Obj.add(new City(Integer.valueOf(city2.get("id")), Integer.valueOf(city2.get("orig_id")), city2.get("name"), Integer.valueOf(city2.get("pid"))));
//}
}
CitySpinnerAdapter city2Adapter =
new CitySpinnerAdapter(AddProspectActivity.this,
android.R.layout.simple_spinner_item, cities2Obj);
//adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
city2Spinner.setTitle("Select City");
city2Spinner.setPositiveButton("OK");
city2Spinner.setAdapter(city2Adapter);
私は私は本当にどこに項目を変更する必要が混乱している。助けてください。私は明らかに希望します。 :(私はcom.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1を使用しています)
はそんなにありがとう:)私はあなたをupvoteするのが大好きだが、私はそれだけの特権を持っていけない... :( – rowrow
ハッピー私は助けることに貢献しました。貴重な助けの代償として私は再ありますSOから守られています。 – ColinWa