I'm a little confused. I must 1. to save the state of the checkbox in the database 2. If the checkbox is turned on - the show avatar
public class MyListAdapter extends ResourceCursorAdapter {
public MyListAdapter(Context context, Cursor cursor) {
super(context, R.layout.list_item, cursor);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView tvName = (TextView)view.findViewById(R.id.name);
CheckBox checkBox = (CheckBox)view.findViewById(R.id.checkBox);
ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
tvName.setText(cursor.getString(1));
checkBox.setChecked((cursor.getInt(2)== 0 ? false:true));
}
}
public class FragmentList extends Fragment{
private ListView listView;
private FloatingActionButton fab;
private Cursor cursor;
private SQLiteDatabase db;
boolean isAvatar;
String nameText;
public FragmentList() {
// Обязателен открытый/публичный пустой конструктор
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_list, container, false);
fab = (FloatingActionButton) v.findViewById(R.id.fab);
listView = (ListView) v.findViewById(R.id.listView);
//создание курсора
try{
SQLiteOpenHelper databaseHelper = new DatabaseHelper(v.getContext());
db = databaseHelper.getWritableDatabase();
Cursor cursor = db.query("PEOPLE", new String[] {"_id", "NAME", "CHECKBOX"}, null, null, null, null, null);
MyListAdapter listAdapter = new MyListAdapter(v.getContext(), cursor);
listView.setAdapter(listAdapter);
} catch (SQLiteException e){
Toast.makeText(v.getContext(), getResources().getString(R.string.db_not_available), Toast.LENGTH_SHORT).show();
}
return v;
}
I'm not shure where i have to do this tasks. I meen in what part of code i have to realize these tasks. May be something else i have to add to my adapter?
Aucun commentaire:
Enregistrer un commentaire