代码:
SimpleCursorAdapter ada = new SimpleCursorAdapter(this,
R.layout.custom_layout, ssCursor, new String[] {
"String" }, new int[] {
R.id.txt2 });
lvSms.setAdapter(ada);
btnDel.setOnClickListener(new View.OnClickListener() {
private ArrayList<String> msgArr;
public void onClick(View v) {
LinearLayout ly = (LinearLayout) findViewById(R.id.lv);
ListView lvMsg = (ListView) ly.getChildAt(3);
int listCount = lvSms.getCount();
for (int a = 0 ; a < listCount ; a++)
{
LinearLayout ll = (LinearLayout) lvMsg.getChildAt(a);
LinearLayout l2 = (LinearLayout) ll.getChildAt(0);
LinearLayout l3 = (LinearLayout) l2.getChildAt(0);
CheckBox chkBox =(CheckBox) l3.getChildAt(0);
boolean valueOfChkBox = chkBox.isChecked();
if (valueOfChkBox) {
LinearLayout l4 = (LinearLayout) l2.getChildAt(1);
TextView txt1 = (TextView) l4.getChildAt(0);
msgArr = new ArrayList<String>();
msgArr.add(txt1.getText().toString());
Log.i("hello", txt1.getText().toString());
}
} });
我得到一个NullPointerException
, asgetChildAt
返回可见行,我还必须检查不可见行,无论它们是否被选中。那么我怎么能在单独的按钮上检查它呢?