I'm trying to make a listview with checkboxes, I have tried a code and it worked correctly but I faced a problem when trying to handle the checkbox states. The problem appears in this line of code
holder.chkBox.setOnCheckedChangeListener((MyActivity) context);
because the code I have tried is using Adapter.java file separated from the MainActivity.java file, but in my code all are in one file so I don't know how to use this line in my code, I have tried this
holder.chkBox.setOnCheckedChangeListener((this) context);
but also a wrong statement
The reason of using this line of holder is that when I checked a checkbox and scroll down through the others items, the checked checkbox is automatically unchecked, Could anyone tell me how to fix this problem?
Here is my Adapter Code
#Override public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder=null;
View itemView = convertView;
if (itemView == null){
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
itemView = inflater.inflate(R.layout.item, null);
holder = new ViewHolder();
holder.textView1 = (TextView) itemView.findViewById(R.id.textView1);
holder.check1 = (CheckBox) itemView.findViewById(R.id.check1);
holder.check2 = (CheckBox) itemView.findViewById(R.id.check2);
itemView.setTag(holder);
}
else{
holder = (ViewHolder) itemView.getTag();
}
holder.check1.setTag(position);
final Item item = items.get(position);
holder.textView1.setText(item.getName());
holder.check1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(buttonView.isPressed()){
if (position != ListView.INVALID_POSITION) {
Item p = items.get(position);
p.setSelected(isChecked);
}
}
}
}
);
holder.check2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(buttonView.isPressed()){
if (position != ListView.INVALID_POSITION) {
Item p = items.get(position);
p.setSelected(isChecked);
}
}
}
}
);
holder.check1.setChecked(item.isSelected());
holder.check2.setChecked(item.isSelected());
return itemView;
}
}private static class ViewHolder {
public TextView textView1;
public CheckBox check2,check1;
}}
First, make your activity implement OnCheckedChangedListener interface, which forces to implement the following method :
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
}
Now pass the reference of your activity to the your adapter as an argument of type OnCheckedChangeListener and name it listener :
MyAdapter myadapter = new MyAdapter(context, MyActivity.this,listdata);
Then, in your adapter class, set the listener for your checkbox like :
holder.chkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(buttonView.isPressed()){
//Write the logic to determine if the checkbox must be checked or not
}
}
}
);
The point here is using the isPressed() method of the checkbox.
It looks like in the example code you worked with, your activity implemented OnCheckedChangeListener, so you needed to pass the context. In your Adapter you can do it as follows:
holder.chkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
// logic
}
}
);
In the code where you had it working, you probably had an overridden onCheckedChanged method in your activity. Move the logic of that where I have // logic above.
Related
My question is similar to this and this. But I cannot apply the solutions in those questions to my case.
My case is as follows: I have GridView consists of just CheckBoxes. I set setOnCheckedChangeListener in my Adapter's getView method, so that as soon as the status of CheckBox is changed, current status of the CheckBox is registered to SharedPreferences. And in getView also, I'm reading the current status of the CheckBox and set its status as so. Yet scrolling down and back up makes the checked boxes unchecked.
How can I solve this problem?
Here is my custom adapter:
public class KnowledgeItemAdapter extends ArrayAdapter<KnowledgeItem> {
private String currentKey;
public KnowledgeItemAdapter(Activity context, ArrayList<KnowledgeItem> knowledgeItems){
super(context, 0, knowledgeItems);
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
View knowledgeItemView = convertView;
if (knowledgeItemView == null){
knowledgeItemView = LayoutInflater.from(getContext()).inflate(R.layout.item_knowledge, parent, false);
}
knowledgeItemView.setClickable(true);
knowledgeItemView.setFocusable(true);
knowledgeItemView.setBackgroundResource(android.R.drawable.menuitem_background);
final KnowledgeItem currentKnowledgeItem = getItem(position);
final CheckBox knowledgeCheckBox = (CheckBox) knowledgeItemView.findViewById(R.id.item_knowledge_check_box);
final SharedPreferences prefs = getContext().getSharedPreferences("com.example.myapplication", Context.MODE_PRIVATE);
currentKey = currentKnowledgeItem.getPrefsKey();
Boolean status = prefs.getBoolean(currentKey, false);
knowledgeCheckBox.setText(currentKnowledgeItem.getText());
knowledgeCheckBox.setChecked(status);
knowledgeCheckBox.setOnCheckedChangeListener( //this);
new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean(currentKnowledgeItem.getPrefsKey(), isChecked).apply();
}
}
);
return knowledgeItemView;
}
}
OK I've figured out the answer finally. I've changed the onCheckedChangeListener with onClickListener.
knowledgeItemView.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.e("On Click Listener", currentKey);
if(knowledgeCheckBox.isChecked()){
knowledgeCheckBox.setChecked(false);
prefs.edit().putBoolean(currentKey, false).apply();
} else {
knowledgeCheckBox.setChecked(true);
prefs.edit().putBoolean(currentKey, true).apply();
}
}
}
);
And do not forget to change the clickable xml attribution of the checkbox to false. Otherwise click events of checkbox and view conflict.
I'am new to android and i use sample for my listview. because of that i can't change the code. i have one switch button in each item of my Listview. when i scroll the Listview switches change state randomly. how can i make switch state stable?
my listview class adapter:
public class MyCustomCursorAdapter extends CursorAdapter {
LIGHTS calling_activity;
private DatabaseHelper dbHelper;
public MyCustomCursorAdapter(Context context, Cursor c) {
super(context, c, 0);
this.calling_activity = (LIGHTS) context;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
return view;
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.adapter,parent,false);
}
#Override
public void bindView(final View view, Context context, Cursor cursor) {
((TextView)view.findViewById(R.id.id)).setText(cursor.getString(cursor.getColumnIndex(dbHelper._ID)));
((TextView)view.findViewById(R.id.KEYCODE)).setText(cursor.getString(cursor.getColumnIndex(dbHelper.TITLE)));
((TextView)view.findViewById(R.id.NAME)).setText(cursor.getString(cursor.getColumnIndex(dbHelper.DESC)));
ImageView option = view.findViewById(R.id.itemoption);
Switch thisswitch = view.findViewById(R.id.onoff);
thisswitch.setTag(cursor.getString(cursor.getColumnIndex(dbHelper._ID)));
thisswitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { calling_activity.myOnCheckedChangedHandler((String)buttonView.getTag(),isChecked);
}
});
option.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView itemID = (TextView) view.findViewById(R.id.id);
TextView itemTitle = (TextView) view.findViewById(R.id.KEYCODE);
TextView itemDesc = (TextView) view.findViewById(R.id.NAME);
String myId = itemID.getText().toString();
String myTitle = itemTitle.getText().toString();
String myDesc = itemDesc.getText().toString();
Intent intent = new Intent(calling_activity, ModifyActivity.class);
intent.putExtra("Id", myId);
intent.putExtra("Title", myTitle);
intent.putExtra("Desc", myDesc);
calling_activity.startActivity(intent);
}
});
}
}
and in my Lights activity :
#Override
public void myOnCheckedChangedHandler(String id, boolean check_status) {
Toast.makeText(
this,
"You changed the status for the row with an id of " + id +
" the status is now " + new Boolean(check_status).toString(),
Toast.LENGTH_SHORT).show();
String name = cursor.getString(cursor.getColumnIndex(dbHelper.DESC));
if(new Boolean(check_status).toString().equals("true")){
Toast.makeText(this,name +" is ON", Toast.LENGTH_SHORT).show();
}
}
Please manage through if/else case inside bindView at adapter, You need to check the switch condition like below :
// set the code into bind
if(switchCondition1 == 1)
{
//set the code as per condition wise
}else{
//
}
After change the state you also need to change the state into your list item and use notifydatasetChanged() method to refresh the list items.
i have a program in which i have multiple questions and 2 options (radiobuttons) when i check 1 and scroll listview it gets unchecked. i will post the whole code kindly fix it for me. I think its something wrong with adapter class
MainActivity
public class MainActivity extends AppCompatActivity {
ListView simpleList;
String[] questions;
Button submit;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get the string array from string.xml file
questions = getResources().getStringArray(R.array.questions);
// get the reference of ListView and Button
simpleList = (ListView) findViewById(R.id.simpleListView);
submit = (Button) findViewById(R.id.submit);
// set the adapter to fill the data in the ListView
CustomAdapter customAdapter = new CustomAdapter(getApplicationContext(), questions);
simpleList.setAdapter(customAdapter);
// perform setOnClickListerner event on Button
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String message = "";
// get the value of selected answers from custom adapter
for (int i = 0; i < CustomAdapter.selectedAnswers.size(); i++) {
message = message + "\n" + (i + 1) + " " + CustomAdapter.selectedAnswers.get(i);
}
// display the message on screen with the help of Toast.
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
});
}
Custom Adapter
public class Questions_Adapter extends BaseAdapter {
Activity context;
String[] questionsList;
String age_range;
LayoutInflater inflter;
public static ArrayList<Integer> selectedAnswers;
public Questions_Adapter(Activity applicationContext, String[] questionsList, String age_range) {
context = applicationContext;
this.questionsList = questionsList;
this.age_range = age_range;
// initialize arraylist and add string for all the questions
selectedAnswers = new ArrayList<>();
for (int i = 0; i < questionsList.length; i++) {
selectedAnswers.add(0);
}
inflter = (LayoutInflater.from(applicationContext));
}
#Override
public int getCount() {
return questionsList.length;
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
private class Viewholder{
TextView question;
RadioButton op1, op2, op3, op4, op5, op6;
}
#Override
public View getView(final int position, View view, ViewGroup viewGroup) {
Viewholder viewholder;
LayoutInflater inflater = context.getLayoutInflater();
if (view == null){
viewholder = new Viewholder();
view = inflater.inflate(R.layout.list_items,null);
viewholder.question = (TextView) view.findViewById(R.id.question);
viewholder.op1 = (RadioButton) view.findViewById(R.id.yes);
viewholder.op2 = (RadioButton) view.findViewById(R.id.no);
viewholder.op3 = (RadioButton) view.findViewById(R.id.op);
viewholder.op4 = (RadioButton) view.findViewById(R.id.op4);
viewholder.op5 = (RadioButton) view.findViewById(R.id.op5);
viewholder.op6 = (RadioButton) view.findViewById(R.id.op6);
view.setTag(viewholder);
}
else {
viewholder = (Viewholder) view.getTag();
}
// perform setOnCheckedChangeListener event on yes button
viewholder.op1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// set Yes values in ArrayList if RadioButton is checked
if (isChecked)
selectedAnswers.set(position, 1);
}
});
viewholder.op2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
selectedAnswers.set(position, 2);
}
});
viewholder.op3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
selectedAnswers.set(position, 3);
}
});
viewholder.op4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
selectedAnswers.set(position, 4);
}
});
viewholder.op5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
selectedAnswers.set(position, 10);
}
});
viewholder.op6.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
selectedAnswers.set(position, 0);
}
});
// set the value in TextView
viewholder.op1.setText("None or Little of a time");
viewholder.op2.setText("Some of the time");
viewholder.op3.setText("A good part of the time");
viewholder.op4.setText("Most or All of the time");
viewholder.op5.setText("Yes");
viewholder.op6.setText("No");
viewholder.question.setText(questionsList[position]);
if(age_range.equals("ZSDS")){
viewholder.op5.setVisibility(View.GONE);
viewholder.op6.setVisibility(View.GONE);
}
if(age_range.equals("GDS")){
viewholder.op1.setVisibility(View.GONE);
viewholder.op2.setVisibility(View.GONE);
viewholder.op3.setVisibility(View.GONE);
viewholder.op4.setVisibility(View.GONE);
}
return view;
}
}
First of all you need to save the tick(checkbox selection) in your model, say isSelected = true & call notifyDataSetChanged. and then inside getView() method u need to check for this flag and set checkbox state based on that.
basically your view is regenerate after every scroll because you are not checking whether view is null or not.
You have to check first view and use holder instead of creating new object of widget every time . here is solution hope , it will work with your listview.
public class CustomAdapter extends BaseAdapter {
static class ViewHolder {
TextView question ;
RadioButton yes,no;
}
Context context;
String[] questionsList;
LayoutInflater inflter;
public static List<String> selectedAnswers;
public CustomAdapter(Context applicationContext, String[] questionsList) {
context = applicationContext;
this.questionsList = questionsList;
// initialize arraylist and add static string for all the questions
selectedAnswers = new ArrayList<>();
for (int i = 0; i < questionsList.length; i++) {
selectedAnswers.add("Not Attempted");
}
inflter = (LayoutInflater.from(applicationContext));
}
#Override
public int getCount() {
return questionsList.length;
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(final int i, View view, ViewGroup viewGroup) {
ViewHolder holder = new ViewHolder();
if(view==null){
view = inflter.inflate(R.layout.list_items, null);
// get the reference of TextView and Button's
holder.question = (TextView) view.findViewById(R.id.question);
holder.yes = (RadioButton) view.findViewById(R.id.yes);
holder.no = (RadioButton) view.findViewById(R.id.no);
// perform setOnCheckedChangeListener event on yes button
view.setTag(holder);
}else{
holder = (ViewHolder) view.getTag();
}
holder.yes.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// set Yes values in ArrayList if RadioButton is checked
if (isChecked)
selectedAnswers.set(i, "Yes");
}
});
// perform setOnCheckedChangeListener event on no button
holder.no.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// set No values in ArrayList if RadioButton is checked
if (isChecked)
selectedAnswers.set(i, "No");
}
});
// set the value in TextView
question.setText(questionsList[i]);
return view;
}
}
When you scroll the view is recycled for displaying the items so the selection of the other old list item that went out of view is coming for the wrong items. So you need to reset the selection for Radio Button when the get view is called.
So you can add the following code in the getVeiw() Method for the selection to work properly
if(position < selectedAnswers.size() && selectedAnswers.get(position) != null) {
switch(selectedAnswers.get(position)) {
case 1:
viewholder.op1.setChecked(true);
break;
case 2:
viewholder.op2.setChecked(true);
break;
case 3:
viewholder.op3.setChecked(true);
break;
case 4:
viewholder.op4.setChecked(true);
break;
case 10:
viewholder.op5.setChecked(true);
break;
case 0:
viewholder.op6.setChecked(true);
break;
default:
viewholder.op1.setChecked(false);
viewholder.op2.setChecked(false);
viewholder.op3.setChecked(false);
viewholder.op4.setChecked(false);
viewholder.op5.setChecked(false);
viewholder.op6.setChecked(false);
}
}
This will set your selection of the radio button on scroll of the listview.
I've been trying to figure out how to use the library MaterialLetterIcon for a while now with no success. I have a custom listview with each item using the image below. An imageview that is selected. This xml file is called da_item.xml
Currently, the imageview(#+id/contactImage) does nothing. Here is my List populator.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = getLayoutInflater().inflate(R.layout.da_item, parent, false);
holder.number = (TextView) convertView.findViewById(R.id.NumberView);
holder.text = (TextView) convertView.findViewById(R.id.NameView);
holder.checkbox = (CheckBox) convertView.findViewById(R.id.checkBox);
holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int getPosition = (Integer) buttonView.getTag(); // Here we get the position that we have set for the checkbox using setTag.
list.get(getPosition).setSelected(buttonView.isChecked()); // Set the value of checkbox to maintain its state.
}
});
convertView.setTag(holder);
convertView.setTag(R.id.NameView, holder.text);
convertView.setTag(R.id.NumberView, holder.number);
convertView.setTag(R.id.checkBox, holder.checkbox);
convertView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
holder.checkbox.setChecked(!holder.checkbox.isChecked());
}
});
holder.text.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
holder.checkbox.setChecked(!holder.checkbox.isChecked());
}
});
holder.number.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
holder.checkbox.setChecked(!holder.checkbox.isChecked());
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.checkbox.setTag(position); // This line is important.
holder.text.setText(list.get(position).getName());
holder.number.setText(list.get(position).getPhone());
holder.checkbox.setChecked(list.get(position).isSelected());
return convertView;
}
I understand how to to add the library, but I am not sure at all how to actually use it. Any suggestions or other libraries to do the same thing would be appreciated too!
Try to use MaterialLetterIcon like this way,this is exactly what you looking for
ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
// generate random color
int color = generator.getColor(getItem(position));
//int color = generator.getRandomColor();
TextDrawable drawable = TextDrawable.builder()
.buildRound(firstLetter, color); // radius in px
For more Check ListViewWithLetterIcon
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.
You can send A Data Using Intent
ArrayList<String> arraylist = new Arraylist<String>();
Intent intent1 = new Intent(MainActivity.this,
LikeActivity.class);
Bundle b = new Bundle();
bundle.putParcelableArrayList("arraylist", arraylist);
intent1.putExtras(b)
if Checked a Checkbox add Item in
arraylist.add("Checked 1");
arraylist.add("Checked 2");
..so on
getting Intent extras on LikeActivity
Intent extras = getIntent();
ArrayList<String> arraylist = extras.getParcelableArrayList("arraylist");
Iterator<String> iterator = arraylist.iterator();
while (iterator.hasNext()) {
// add Item on ListActivity //iterator.next()
}
You can have this changes in checkbox code in adapter class
ArrayList<String> checkedSelection = new ArrayList<String>();
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
// add into arraylist
checkedSelection.add(holder.checkBox.getText().toString());
}else{
// remove from arraylist
checkedSelection.remove(position);
}
}
});
after that send arraylist from mainactivity by using following intent
Intent i=new Intent(this,Route.class);
i.putStringArrayListExtra("list", ar);
startActivity(i);
and get that arraylist in 2nd activity like,
ArrayList<String> ar1=getIntent().getExtras().getStringArrayList("list");
1.If you dont want immediate jump to MainActivity after the selection then Intent cant be a good choice.
Use a static boolean variable inside your main activity and set the value of that variable inside Adapter using MainActivity.isChecked = true/false ;
Thanks for the tips and sharing. I already get the solution. Here my code and step:
Add this code into if statement to add details into database
#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) {
Name name = new Name(nameArrayList.get(position).getName(),
nameArrayList.get(position).getGender(),
nameArrayList.get(position).getEng(),
nameArrayList.get(position).getMy());
name.save();
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;}
Create LikeAdapter.java to view the selected row in LikeActivity.class
Keep moving!
In progress...