我有一個列表視圖和BaseAdapter添加一個圖像和一個文本行。我的問題是我如何加載列表視圖中的圖像根據文本name.i知道如果我根據文本數組添加圖像到數組我可以完成這項工作。但是從服務call.Every時間的文字排列順序我的文字串負荷然後改變我的形象的加載順序是不是correct..so可以在任何一個點我有辦法讓這個done.Thank你如何根據文本名稱加載列表視圖中的圖像
BaseAdapter類
public class MenuListAdapter extends BaseAdapter {
private Context context;
private List<String> mtitle;
private int[] micon;
private LayoutInflater inflater;
Typeface tf;
public MenuListAdapter(Context context, List<String> modules, int[] icon) {
this.context = context;
this.mtitle = modules;
this.micon = icon;
}
@Override
public int getCount() {
return mtitle.size();
}
@Override
public Object getItem(int arg0) {
return arg0;
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int position, View arg1, ViewGroup parent) {
TextView title;
ImageView icon;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.nav_drawer_list_item, parent,
false);
title = (TextView) itemView.findViewById(R.id.title);
icon = (ImageView) itemView.findViewById(R.id.icon);
Typeface type = Typeface.createFromAsset(context.getAssets(),"fonts/font.ttf");
title.setText(mtitle.get(position));
title.setTypeface(type);
icon.setImageResource(micon[position]);
return itemView;
}
}
圖像陣列
private int[] photo;
photo = new int[]{R.drawable.btn_0011_home,R.drawable.btn_0010_accounts, R.drawable.btn_0009_contacts, R.drawable.btn_0008_opportunities,
R.drawable.btn_0007_leads,R.drawable.btn_0006_calendar,R.drawable.btn_0005_documents,R.drawable.btn_0004_emails,R.drawable.btn_0003_campaigns, R.drawable.btn_0002_calls, R.drawable.btn_0001_meeting,
R.drawable.btn_0000_tasks, R.drawable.ic_launcher}
MenuListAdapter menuAdapter = new MenuListAdapter(
getApplicationContext(), moduleName, photo);
檢查MODULENAME,照片都r等於 – Jai 2015-03-31 05:39:49
我怎麼能檢查。 .i將圖像添加爲R.drawable.btn_001 – kosala 2015-03-31 05:43:43
嘗試添加邏輯以動態地爲標題找到適當的圖像。那可能嗎? – deniz 2015-03-31 05:47:16