代码:NullPointerException异常而穿越一个ListView
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
,为getChildAt
返回可见行,我也必须检查无形行,他们要么被选中或不。那么我怎么能在单独的按钮上检查它?
你可以添加代码设置适配器(或者如果它是一个自定义适配器添加代码)? – Luksprog
@Luksprog我已根据您的要求添加了适配器代码。请帮助... – kamil
你想完成什么?一般来说不是代码方式。 – Barak