我想修改我的ListView使其:創建多選擇自定義的ListView
- 包含圖片
- 包含文字說明(文件名)
- 包含一個複選框。
該列表應該是多選的。我應該能夠遍歷所有選中的複選框並獲取描述。
目前,我可以用複選框顯示一個普通的ListView。
ArrayAdapter<String> ad = new ArrayAdapter<String>(HelloDropboxActivity.this, android.R.layout.simple_list_item_multiple_choice,fileName);
mTestListOutput.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
mTestListOutput.setAdapter(ad);
使用的onclick一個Button
- 我可以通過檢查箱子循環並獲得文成這樣一個ArrayList:
ArrayList<String> dbLinks = new ArrayList<String>();
int cntChoice = mTestListOutput.getCount();
SparseBooleanArray sparseBooleanArray = mTestListOutput.getCheckedItemPositions();
for(int i = 0; i < cntChoice; i++)
{
if(sparseBooleanArray.get(i) == true)
{
dbLinks.add(mTestListOutput.getItemAtPosition(i).toString());
}
}
我retreving的ArrayList: 私人ArrayList的路徑;
那麼我該如何將這些綁在一起來創建一個自定義的ListView? 我看了很多例子,並試圖修改它們,但我無處可去。
這裏我attampted在我list_row.xnl創建列表行的佈局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<!-- Thumbnail image -->
<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip">
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
/>
</LinearLayout>
<!-- File Name -->
<TextView
android:id="@+id/filename"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:textColor="#343434"
android:textSize="10dip"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
android:text="Just gona stand there and ..." />
</RelativeLayout>
謝謝我會試試這個 - 但什麼是私人CheckedTextReadventureView _checkbox,以及如何更改我的代碼使用它?和_checkbox.isChecked()定義在哪裏? – user3437721
那是我的一個自定義複選框,我沒有注意到當我複製代碼時。現在更改答案,以便它使用標準複選框。 – CurlyPaul
謝謝 - 我是否需要在xml中更改它以成爲我的包,例如
user3437721