首先,您需要爲您的列表條目定製佈局。包含ImageView,TextView和CheckBox的簡單RelativeLayout應該就足夠了。
然後,您可能需要構建自己的可以擴展BaseAdapter(或SimpleAdapter或CursorAdapter或ArrayAdapter或...)的自定義適配器。適配器會將列表數據綁定到您的自定義佈局。例如,如果您的數據包含在一個光標它看起來像:
private class MyCustomAdapter extends CursorAdapter {
public MyCustomAdapter(Context context) {
super(context, null);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
//Return a list item view
return getLayoutInflater().inflate(R.layout.my_custom_list_item_layout, parent, false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
//Get views from layout
final ImageView imageView = (ImageView) view.findViewById(R.id.list_item_image);
final TextView textView = (TextView) view.findViewById(R.id.list_item_text);
final CheckBox checkBox = (CheckBox) view.findViewById(R.id.list_item_checkbox);
//Get data from cursor
final String text = cursor.getString(...);
//Add listener to the checkbox
checkBox.setOnClickListener(new OnClickListener() {...});
//Bind data
textView.setText(text);
}
}
來源
2012-05-03 12:23:18
Ika
我不明白你有什麼問題。您不知道如何設置刪除機制,或者問題出現在您的行佈局構建中? – Luksprog
問題是,我無法正確設置佈局(xml)。我希望中間部分(消息標題和日期)具有動態寬度。左側是帶有48傾角的圖標,右側是複選框,也是固定的。每次im複選框添加到xml它不顯示。 – KeepAlive