2011-01-25 7 views
1

ImageViewTextViewというチェックボックスのリストを表示したいと思います。アイコンと名前(アンドロイド)のチェックボックスの表示方法

+-----------+----------+----------+ 
| CHECK_BOX | ImageVew | TextView | 
+-----------+----------+----------+ 

このリストは複数選択可能です。
このリストの作成方法?
選択したすべてのチェックボックスと対応するTextView値を取得するにはどうすればよいですか?

これについては、サンプルコードを提供してください。

ありがとう、
PPです。

答えて

1

アダプタを作成し、リストビューにバインドを参照してください。レイアウトは簡単です(水平方向のLinearLayout)。 BaseAdapterクラスを拡張する必要があります。

public class BasicClass { 

// Holds the ID for the row 
public int ID; 

// Holds the resource ID for the imageview 
public int ImageID; 

// Holds the text for the textview 
public String Text; 

}

あなたのGetViewメソッドは次のようなものになります:

public View getView(final int position, View convertView, ViewGroup parent) { 
    View v = convertView; 
    final BasicClass e = (BasicClass) getItem(position); 

    if (v == null) { 
     LayoutInflater vi = (LayoutInflater) mContext 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     v = vi.inflate(R.layout.checkbox_list_item, null); 
    } 


    TextView txtTitle = (TextView)v.findViewById(R.id.checkbox_list_item_txtTitle); 
    ImageView img = (ImageView)v.findViewById(R.id.checkbox_list_item_img); 
    final CheckBox chSelected = (CheckBox)v.findViewById(R.id.checkbox_list_item_cbSelected); 

    txtTitle.setText(e.Text); 
    img.setBackgroundDrawable(mContext.getResources().getDrawable(e.ImageID)) 

    chSelected.setOnCheckedChangeListener(new OnCheckedChangeListener() { 

     @Override 
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       //Logic comes here to add and remove the selected items to a ArrayList<BasicCLass> 

     } 
    }); 


    return v; 
} 

は、データを保持し、あなたのクラスは次のようになりますと仮定します

1

BaseAdapterクラスを拡張してListviewカスタムアダプタを使用する方がよい。
複数の選択については、このlinks
を参照してくださいはthis

関連する問題