I'm using CheckBox to insert data from MainActivity to LikeActivity. I already use this code in myAdapter.java:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_name, null);
// Get TextView
TextView tvName = (TextView) convertView.findViewById(R.id.tvName);
TextView tvEng = (TextView) convertView.findViewById(R.id.tvEng);
TextView tvMy = (TextView) convertView.findViewById(R.id.tvMy);
CheckBox cbFavorite = (CheckBox) convertView.findViewById(R.id.cbFavorite);
cbFavorite.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
// Check if it is favorite or not
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
Toast.makeText(context.getApplicationContext(), "Add to Favorite", Toast.LENGTH_LONG).show();
Log.e("set", "true");
} else {
Toast.makeText(context.getApplicationContext(), "Remove from Favorite", Toast.LENGTH_LONG).show();
Log.e("set", "false");
}
}
});
return convertView;
}
Next, my question is how to put coding for add and remove function in if statement. So, when user tick in checkbox in MainActivity the selected item will add to LikeActivity and when untick the selected item will remove from LikeActivity.
Thanks.
Aucun commentaire:
Enregistrer un commentaire