私はsqliteで作業し、2つの列(名前、アイコン)から結果を取得します。名前を (TextView) のテキストとして設定し、次にsetCompoundDrawablesWithIntrinsicBoundsを使用してアイコンを drawableLeft として設定するように、それらをカスタム アダプターに渡したいと考えています。
まず第一に、私のdbへの挿入はこのようなものです
"Fruit / Vegetables,R.drawable.ic_launcher",
"Meat / Fisth,R.drawable.ic_launcher"
私のlistActivityには、dbなどを開いた後にこのコードがあります..
mShopCatCursor = mDbHelper.fetchShoppingCategories();
startManagingCursor(mShopCatCursor);
String[] names,icons;
while(mShopCatCursor.moveToNext()){
for(int i=-1,l=mShopCatCursor.getColumnCount(); ++i<l;){
names[i]= mShopCatCursor.getString(0);
icons[i]= mShopCatCursor.getString(1);
}
}
//this was taken from a tut
String[] from = new String[]{AppSQLite.KEY_NAME,AppSQLite.KEY_ICON};
TextViewWithDrawableListAdapter adap =
new TextViewWithDrawableListAdapter(this, from);
setListAdapter(adap);
私が望むのは、カスタムアダプターが次のことを行うように、名前とアイコンを渡すことです
public View getView(int position, View convertView, ViewGroup parent){
View v = convertView;
if(v == null){
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.main_list_item, null);
}
TextView textView = (TextView) v.findViewById(R.id.main_menu_list_item);
これ欲しい!!各リスト項目が正しい値を取るようにします。
textView.setText(names[0]);
textView.setCompoundDrawablesWithIntrinsicBounds(icons[0], 0, 0, 0);
return v;
}
namew[0] と icon が間違っていることは知っていますが、ウェブを何時間も検索しても、本当に道がわかりません。