0
我有一個微調控件,我從一個繼承自BaseAdapter的類中填充。我可以使用這個適配器類來填充微調,但它顯示2列,我只喜歡一個。例如,它目前顯示:Android - 僅在適配器中顯示Spinner的值1
John Brown [email protected]
Sue Fields [email protected]
Mark Twain [email protected]
而且我也喜歡,只顯示:
John Brown
Sue Fields
Mark Twain
下面是我的適配器代碼:
public class POCInfoAdapter extends BaseAdapter {
//Private objects.
private List<POCInfo> mListPOCInfo;
private LayoutInflater mInflater;
//constructor.
public POCInfoAdapter(Context c, List<POCInfo> list){
mListPOCInfo = list;
//create layout inflater.
mInflater = LayoutInflater.from(c);
}
@Override
public int getCount(){
return mListPOCInfo.size();
}
@Override
public Object getItem(int position){
return mListPOCInfo.get(position);
}
@Override
public long getItemId(int position){
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
//Get view reference.
View view = convertView;
//If view is null.
if(view == null){
//Inflate new layout.
view = mInflater.inflate(R.layout.poc_list, null);
//create holder.
ViewHolder holder = new ViewHolder();
//Find Controls.
holder.txtFullName = (TextView)view.findViewById(R.id.txtFullName);
holder.txtEmailAddress = (TextView)view.findViewById(R.id.txtEmailAddress);
//Set data structure to view.
view.setTag(holder);
}
//Get selected POC Info.
POCInfo pocInfo = mListPOCInfo.get(position);
if(pocInfo != null){
//query data structure.
ViewHolder holder = (ViewHolder)view.getTag();
//Set data to display.
holder.txtFullName.setText(pocInfo.getFullName());
holder.txtEmailAddress.setText(pocInfo.getEmailAddress());
}
return view;
}
//Class to hold data structure on view with POC Information.
static class ViewHolder{
private TextView txtFullName;
private TextView txtEmailAddress;
}
}
並填充碼spinner:
Spinner spSpinner = (Spinner)findViewById(R.id.spPOCs);
spSpinner.setAdapter(new POCInfoAdapter(this, DBAdapter.queryAll()));
DBA dapter.queryAll()返回一個POCInfo類型的列表。 POCInfoAdapter類也被許多其他需要電子郵件地址的活動使用,因此我不能只是將getView()更改爲僅返回FullName。
任何想法?
刪除此行holder.txtEmailAddress =(TextView的)view.findViewById(R.id.txtEmailAddress)膨脹該佈局; – 2012-03-07 16:03:59
正如我在OP的第二行到最後一行所說的那樣,我無法更改getView,因爲這個類在其他需要的活動中使用。 – Robert 2012-03-07 16:06:14
...然後創建一個類的副本,並將其刪除並使用該...或有一個標誌,將隱藏它,並相應地設置該標誌 – jsimpson 2012-03-07 16:07:41