我已經創建了自定義列表視圖,其中包含Imageview + TextView +複選框 現在我的問題是,我必須得到哪一行的複選框被選中。Android自定義列表視圖
的Xml row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:orientation="horizontal" android:layout_width="fill_parent"
android:gravity="center_vertical" android:layout_height="60dip">
<LinearLayout android:id="@+id/LinearLayout03"
android:orientation="vertical" android:gravity="center_vertical"
android:layout_marginLeft="10dip" android:layout_height="60dip"
android:layout_width="260dip">
<TextView android:id="@+id/desc" android:layout_width="fill_parent"
android:layout_height="40dip" android:ellipsize="marquee"
android:text="Text" android:textSize="20dip" android:textStyle="bold"
android:gravity="center_vertical" android:textColor="@color/black" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Phone number"
android:id="@+id/phone_no" android:textColor="@color/black"></TextView>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="fill_parent" android:gravity="center_vertical"
android:layout_height="60dip">
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/chk_number"></CheckBox>
</LinearLayout>
</LinearLayout>
和適配器是:
class ContactList extends ArrayAdapter{
Activity context;
public ContactList(Activity context) {
super(context, R.layout.row,names);
this.context = context;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View row = inflater.inflate(R.layout.row, null);
TextView Name = (TextView) row.findViewById(R.id.desc);
TextView Number = (TextView) row.findViewById(R.id.phone_no);
Name.setText(names.get(position));
Number.setText(numbers.get(position));
CheckBox checkboxnumberScramble = (CheckBox) row.findViewWithTag(R.id.chk_number);
checkboxnumberScramble.setChecked(true);
checkboxnumberScramble.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if (isChecked) {
setCheckboxflag(true);
}else{
setCheckboxflag(false);
}
}
});
return (row);
}
}
我得到的異常在我活動的onCreate。
什麼是例外(從'adb logcat'粘貼)? – 2010-04-02 14:13:03
請打印logerror。 – 2011-10-01 04:34:58