0

私は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 が間違っていることは知っていますが、ウェブを何時間も検索しても、本当に道がわかりません。

4

1 に答える 1

0

まず第一に、あなたが何を望んでいるのかはっきりしません。名前とアイコンの配列をカスタム アダプター クラスに渡したい場合は、カスタム アダプター クラスでコンストラクターを使用してそれらを受け取ることができます。または、このチュートリアルをお読みください。

于 2012-01-24T16:26:07.347 に答える