我有以下代码
public class Contacts extends ListActivity {
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor cursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
startManagingCursor(cursor);
String[] from = { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone._ID };
int[] to = { android.R.id.text1, android.R.id.text2 };
ListAdapter listadapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_multiple_choice, cursor,
from, to);
setListAdapter(listadapter);
lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setItemsCanFocus(false);
lv.setTextFilterEnabled(true);
final int check = lv.getCheckedItemPosition();//lv.getCheckedItemIds();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
TextView tv = (TextView) arg1.findViewById(android.R.id.text2);
String aa = (String) tv.getText();
String ab = lv.getItemAtPosition(arg2).toString();
int ac = lv.getSelectedItemPosition();
System.out.println("wow "+ab +" ww "+ ac + " "+ aa);
Toast.makeText(Contacts.this, ((TextView) arg1).getText(), Toast.LENGTH_LONG).show();
}
});
}
}
我想阅读ListView
到目前为止我无法做到的数字部分。我什至尝试过
TextView tv = (TextView) arg1.findViewById(android.R.id.text2);
String test = tv.getText().toString();
,但NullPointerException
基本上我总是想从手机的联系人列表中获取所有联系人,这样我就可以一次选择多个联系人。请帮忙!