ListView 布局中的复选框对于被单击的记忆非常短
下面显示联系人姓名的代码效果不错:
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class Authorize_Activity extends ListActivity {
Cursor mContacts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Return all contacts, ordered by name
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME }; // Would like the phone num, too
mContacts = managedQuery(ContactsContract.Contacts.CONTENT_URI,
projection, null, null, ContactsContract.Contacts.DISPLAY_NAME);
// Display all contacts in a ListView
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_multiple_choice, mContacts,
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { android.R.id.text1 });
setListAdapter(mAdapter);
}
}
..但是与姓名一起显示的复选框(通过本机 simple_list_item_multiple_choice 布局)不会保留单击 - 当您按下该复选框时,该复选框将保持选中状态,但不会保留似乎保持单击状态(要么是黑色背景下的复选框是黑色的,就像黑豹上的斑点,但我看不到它)。
我看到其他人过去也遇到过这个问题,但是与前面提到的复杂的解决方法相比,必须有一种不那么老套/笨拙的方法来解决这个问题。毕竟,如果您无法选中复选框,那么它有什么用呢?
The code below to display Contact names works somewhat well:
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class Authorize_Activity extends ListActivity {
Cursor mContacts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Return all contacts, ordered by name
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME }; // Would like the phone num, too
mContacts = managedQuery(ContactsContract.Contacts.CONTENT_URI,
projection, null, null, ContactsContract.Contacts.DISPLAY_NAME);
// Display all contacts in a ListView
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_multiple_choice, mContacts,
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { android.R.id.text1 });
setListAdapter(mAdapter);
}
}
..but the check boxes displayed with the names (via the native simple_list_item_multiple_choice layout) won't retain a click - the checkbox remains checked while you're pressing on it, but does not seem to remain clicked (either that, or the checkbox is black against a black background, like spots on a black panther, and I can't see it).
I see other people have had this issue in the past, too, but there HAS to be a less hacky/kludgy way of getting this to work than the complex workarounds that were mentioned. After all, what's the use of a check box if you can't check it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了获得更好的性能和处理能力,您应该使用 BaseAdapter 类和普通 Listview。我认为当您想要自定义操作或设计时,使用 ListActivity 并不是一个好主意。这在操作和设计方面的能力都有限
已编辑
查看此链接了解适配器列表视图创意
For Better performance and handling you should use BaseAdapter class and Normal Listview.I think using ListActivity is not a good idea when you want to customize your action or design.This has limited power in terms of both action and design
Edited
See this link for adapter listview idea