我希望用来String aa=c.getString(c.getColumnIndex("address"))
获取函数中某项的列值private void SetSelectedAndTotal
。
但是应用程序崩溃了,我该怎么办?谢谢!
private ListView lv;
private TextView selectedAndTotal;
private void InitListView() {
List<String> msgList = getSMS();
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, msgList);
lv.setAdapter(adapter2);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
SetSelectedAndTotal(arg2);
}
});
}
private void SetSelectedAndTotal(int arg2){
Cursor c = (Cursor) lv.getItemAtPosition(arg2);
String aa=c.getString(c.getColumnIndex("address"));
selectedAndTotal.setText(aa);
}
public List<String> getSMS() {
List<String> sms = new ArrayList<String>();
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,
null);
while (cur.moveToNext()) {
String address = cur.getString(cur.getColumnIndex("address"));
String body = cur.getString(cur.getColumnIndexOrThrow("body"));
sms.add("Number: " + address + " .Message: " + body);
}
return sms;
}