1
私は今、ロードするカスタム行を取得しようとしていました。 StackOverflowやその他の場所では、Androidのリストビュー内のデータ行にチェックボックスをバインドする方法がたくさんあるようですが、すべてが不完全であるようです。チェックボックスの付いたAndroidリストビュー
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="40dip"
android:orientation="horizontal" android:background="@drawable/row_bk"
android:layout_gravity="center_vertical">
<TextView android:id="@+id/ItemID"
android:layout_weight="0" android:visibility="gone"
android:layout_width="0dp" android:gravity="center"
android:layout_height="wrap_content" />
<TextView android:id="@+id/Title"
android:layout_width="0dp" android:textColor="#666"
android:layout_weight="1" android:layout_height="40dip"
android:padding="5dp" android:gravity="center_vertical"
android:textSize="17dip" />
<CheckBox android:id="@+id/chkCheck" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:focusable="false" android:focusableInTouchMode="false" android:clickable="true"></CheckBox>
</LinearLayout>
はコードでは、私はListViewコントロールを移入、SimpleCursorAdapterあります
は、ここで私は(row.xml)を持っているものです。
Cursor oLoop = db
.rawQuery(
"select _id, title, is_checked from tbl",null);
startManagingCursor(oLoop);
String[] from = new String[] { "_id", "title", "is_checked" };
int[] to = new int[] { R.id.ItemID, R.id.Title, R.id.chkCheck };
SimpleCursorAdapter oList =
new SimpleCursorAdapter (this, R.layout.task_item_row, oLoop, from,
to);
setListAdapter(oList);
これ以前は何をすべきかわかりません。誰かが私に良い例を教えてもらえると、それは素晴らしいことになるでしょう。目標は、実際にチェックボックスを切り替えることです。
ありがとうございます!
がgetViewAdapter().setViewBinder(
new ViewBinder(){
public boolean setViewAdapter(View view, Cursor cursor, int columnIndex){
<JavaType> object = cursor.get<JavaType>(columnIndex);
boolean isHandled = false;
if(view.getId() == R.id.checkBox){
CheckBox cb = (CheckBox) view;
cb.setChecked(isObjectChecked(object));
// object depends on your underlying data type
// in the data base, use the debugger to find the actually implemented type.
isHandled = true;
}
return isHandled;
}
}
);
これは条件付きで見える景色や負荷で非常に強力な方法であることができます: アレックス
うん、それでした!それは私が行方不明だった作品です!間違いなく、明白なステップでもありません。私は後世のためにこれをどこかに書かなければならないでしょう。 – LTMOD
@LTMOD [SimpleAdapter](http://developer.android.com/reference/android/widget/SimpleAdapter.html)のドキュメントにあります。 –