这是我的自定义CursorAdapter:
public class TasksAdapter extends CursorAdapter implements Filterable {
private final Context context;
public TasksAdapter(Context context, Cursor c) {
super(context, c);
this.context = context;
}
/**
* @see android.widget.CursorAdapter#newView(android.content.Context, android.database.Cursor, android.view.ViewGroup)
*/
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(android.R.layout.simple_list_item_checked, parent, false);
ViewHolder holder = new ViewHolder();
holder.textview = (CheckedTextView)v.findViewById(android.R.id.text1);
v.setTag(holder);
return v;
}
/**
* @see android.widget.CursorAdapter#bindView(android.view.View, android.content.Context, android.database.Cursor)
*/
@Override
public void bindView(View view, Context context, Cursor cursor) …Run Code Online (Sandbox Code Playgroud) 我正在使用CursorAdapter在listview中读取数据库.我在列表的每个项目中都有一个复选框,当用户选中复选框时,我的数据库中的收藏列会更改是,并且项目会添加到收藏夹中.
一切都很好,最喜欢的列已更改,但当我在列表中向上和向下滚动时,复选框将取消选中.如果您重新启动应用程序,则复选框已被选中
我该怎么办这个问题:
对不起,我的英语不好:
CursorAdapter类:
public class MyAdapter extends CursorAdapter {
Context b;
LayoutInflater inflater;
@SuppressWarnings("deprecation")
public MyAdapter(Context context, Cursor c) {
super(context, c);
inflater = LayoutInflater.from(context);
b= (Context) context;
}
@SuppressWarnings("unused")
@Override
public void bindView(View view, Context context, final Cursor cursor) {
// TODO Auto-generated method stub
TextView tv1 = (TextView)view.findViewById(R.id.txt_name);
TextView tv2 = (TextView)view.findViewById(R.id.txt_numer);
tv1.setText(cursor.getString(2));
tv2.setText(cursor.getString(3));
final int pos = cursor.getPosition();
final CheckBox repeatChkBx = (CheckBox)view.findViewById(R.id.favorite_check);
String me = cursor.getString(cursor.getColumnIndex("like"));
if (me.equals("yes")) {
repeatChkBx.setChecked(true);
} else {
repeatChkBx.setChecked(false); …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个edittext和listview我的listview显示联系人列表.我想要使用edittext的listview过滤器.我在谷歌搜索了很多,发现了一些考试,但没有一个适合我,这里是我的代码
我的自定义适配器
public class ContactListAdapter extends ArrayAdapter {
private final Activity activity;
private final List<ContactStock> stocks;
private ArrayList<ContactStock> arraylist;
public ContactListAdapter(Activity activity, List<ContactStock> objects) {
super(activity, R.layout.listview_detail, objects);
this.activity = activity;
this.stocks = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View rowView = convertView;
ContactStockView sv = null;
if (rowView == null) {
// Get a new instance of the row layout view
LayoutInflater inflater = activity.getLayoutInflater();
rowView = inflater.inflate( …Run Code Online (Sandbox Code Playgroud)