Hi to all, today we are going to learn how to enable multiple items to be chosen in ListView, GridView and in RecyclerView using CheckBox, you’ll configure the ListView to display a checkbox next to each item. You can combine many components like TextView, CheckBox, ImageView, etc. and can make ListView as you require.
In this tutorial, we are going to learn how to enable multiple items to be chosen in ListView, GridView and in RecyclerView using CheckBox.
1. Create a new project in Android Studio by navigating to File ⇒ New ⇒ New Project and fill required details. By default my activity is MainActivity.java.
2. Open build.gradle and include this libraries show below:
1 2 |
compile 'com.android.support:design:25.1.0' //Library need for material tabs compile 'com.android.support:recyclerview-v7:25.1.0' //Library need for recycler view |
3. Now create 3 material tabs naming ListView, GridView and RecyclerView. For this you can check this link for reference.
4. After creating tabs lets move to creating xml layouts for individual tabs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp"> <ListView android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/bottom_container" /> <include android:id="@+id/bottom_container" layout="@layout/bottom_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> </RelativeLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp"> <GridView android:id="@+id/grid_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/bottom_container" android:horizontalSpacing="2dp" android:numColumns="2" android:verticalSpacing="2dp" /> <include android:id="@+id/bottom_container" layout="@layout/bottom_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> </RelativeLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/bottom_container" /> <include android:id="@+id/bottom_container" layout="@layout/bottom_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> </RelativeLayout> |
5. In all the above xml layouts i am using one common layout i.e. bottom_container.xml. Lets create the common layout xml, this layout contains three buttons for implementing actions over selected rows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> <Button android:id="@+id/show_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/show" android:textColor="@android:color/black" android:textSize="14sp" /> <Button android:id="@+id/delete_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/delete" android:textColor="@android:color/black" android:textSize="14sp" /> <Button android:id="@+id/select_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/select_all" android:textColor="@android:color/black" android:textSize="14sp" /> </LinearLayout> |
6. Now lets create java classes for all the above three xml files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
package com.listcheckbox_demo.main; import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.util.SparseBooleanArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ListView; import android.widget.Toast; import com.listcheckbox_demo.R; import com.listcheckbox_demo.adapter.GridListAdapter; import java.util.ArrayList; /** * Created by sonu on 08/02/17. */ public class ListViewFragment extends Fragment { private Context context; private GridListAdapter adapter; private ArrayList<String> arrayList; private Button selectButton; public ListViewFragment() { } @Override public void onAttach(Context context) { super.onAttach(context); this.context = context; } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.list_view_fragment, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); selectButton = (Button) view.findViewById(R.id.select_button); loadListView(view); onClickEvent(view); } private void loadListView(View view) { ListView listView = (ListView) view.findViewById(R.id.list_view); arrayList = new ArrayList<>(); for (int i = 1; i <= 50; i++) arrayList.add("ListView Items " + i);//Adding items to recycler view adapter = new GridListAdapter(context, arrayList, true); listView.setAdapter(adapter); } private void onClickEvent(View view) { view.findViewById(R.id.show_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SparseBooleanArray selectedRows = adapter.getSelectedIds(); if (selectedRows.size() > 0) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < selectedRows.size(); i++) { if (selectedRows.valueAt(i)) { String selectedRowLabel = arrayList.get(selectedRows.keyAt(i)); stringBuilder.append(selectedRowLabel + "\n"); } } Toast.makeText(context, "Selected Rows\n" + stringBuilder.toString(), Toast.LENGTH_SHORT).show(); } } }); view.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SparseBooleanArray selectedRows = adapter.getSelectedIds(); if (selectedRows.size() > 0) { for (int i = (selectedRows.size() - 1); i >= 0; i--) { if (selectedRows.valueAt(i)) { arrayList.remove(selectedRows.keyAt(i)); } } adapter.removeSelection(); } } }); selectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //Check the current text of Select Button if (selectButton.getText().toString().equals(getResources().getString(R.string.select_all))) { //If Text is Select All then loop to all array List items and check all of them for (int i = 0; i < arrayList.size(); i++) adapter.checkCheckBox(i, true); //After checking all items change button text selectButton.setText(getResources().getString(R.string.deselect_all)); } else { //If button text is Deselect All remove check from all items adapter.removeSelection(); //After checking all items change button text selectButton.setText(getResources().getString(R.string.select_all)); } } }); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
package com.listcheckbox_demo.main; import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.util.SparseBooleanArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.GridView; import android.widget.Toast; import com.listcheckbox_demo.R; import com.listcheckbox_demo.adapter.GridListAdapter; import java.util.ArrayList; /** * Created by sonu on 08/02/17. */ public class GridViewFragment extends Fragment { private Context context; private GridListAdapter adapter; private ArrayList<String> arrayList; private Button selectButton; public GridViewFragment() { } @Override public void onAttach(Context context) { super.onAttach(context); this.context = context; } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.grid_view_fragment, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); selectButton = (Button) view.findViewById(R.id.select_button); loadGridView(view); onClickEvent(view); } private void loadGridView(View view) { GridView gridView = (GridView) view.findViewById(R.id.grid_view); arrayList = new ArrayList<>(); for (int i = 1; i <= 50; i++) arrayList.add("GridView Items " + i); adapter = new GridListAdapter(context, arrayList, false); gridView.setAdapter(adapter); } private void onClickEvent(View view) { view.findViewById(R.id.show_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SparseBooleanArray selectedRows = adapter.getSelectedIds(); if (selectedRows.size() > 0) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < selectedRows.size(); i++) { if (selectedRows.valueAt(i)) { String selectedRowLabel = arrayList.get(selectedRows.keyAt(i)); stringBuilder.append(selectedRowLabel + "\n"); } } Toast.makeText(context, "Selected Rows\n" + stringBuilder.toString(), Toast.LENGTH_SHORT).show(); } } }); view.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SparseBooleanArray selectedRows = adapter.getSelectedIds(); if (selectedRows.size() > 0) { for (int i = (selectedRows.size() - 1); i >= 0; i--) { if (selectedRows.valueAt(i)) { arrayList.remove(selectedRows.keyAt(i)); } } adapter.removeSelection(); } } }); selectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //Check the current text of Select Button if (selectButton.getText().toString().equals(getResources().getString(R.string.select_all))) { //If Text is Select All then loop to all array List items and check all of them for (int i = 0; i < arrayList.size(); i++) adapter.checkCheckBox(i, true); //After checking all items change button text selectButton.setText(getResources().getString(R.string.deselect_all)); } else { //If button text is Deselect All remove check from all items adapter.removeSelection(); //After checking all items change button text selectButton.setText(getResources().getString(R.string.select_all)); } } }); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
package com.listcheckbox_demo.main; import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.SparseBooleanArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.Toast; import com.listcheckbox_demo.R; import com.listcheckbox_demo.adapter.RecyclerViewAdapter; import java.util.ArrayList; /** * Created by sonu on 08/02/17. */ public class RecyclerViewFragment extends Fragment { private Context context; private RecyclerViewAdapter adapter; private ArrayList<String> arrayList; private Button selectButton; public RecyclerViewFragment() { } @Override public void onAttach(Context context) { super.onAttach(context); this.context = context; } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.recycler_view_fragment, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); selectButton = (Button) view.findViewById(R.id.select_button); populateRecyclerView(view); onClickEvent(view); } private void populateRecyclerView(View view) { RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context); recyclerView.setLayoutManager(linearLayoutManager); arrayList = new ArrayList<>(); for (int i = 1; i <= 50; i++) arrayList.add("RecyclerView Items " + i);//Adding items to recycler view adapter = new RecyclerViewAdapter(context, arrayList); recyclerView.setAdapter(adapter); } private void onClickEvent(View view) { view.findViewById(R.id.show_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SparseBooleanArray selectedRows = adapter.getSelectedIds(); if (selectedRows.size() > 0) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < selectedRows.size(); i++) { if (selectedRows.valueAt(i)) { String selectedRowLabel = arrayList.get(selectedRows.keyAt(i)); stringBuilder.append(selectedRowLabel + "\n"); } } Toast.makeText(context, "Selected Rows\n" + stringBuilder.toString(), Toast.LENGTH_SHORT).show(); } } }); view.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { SparseBooleanArray selectedRows = adapter.getSelectedIds(); if (selectedRows.size() > 0) { for (int i = (selectedRows.size() - 1); i >= 0; i--) { if (selectedRows.valueAt(i)) { arrayList.remove(selectedRows.keyAt(i)); } } adapter.removeSelection(); } } }); selectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //Check the current text of Select Button if (selectButton.getText().toString().equals(getResources().getString(R.string.select_all))) { //If Text is Select All then loop to all array List items and check all of them for (int i = 0; i < arrayList.size(); i++) adapter.checkCheckBox(i, true); //After checking all items change button text selectButton.setText(getResources().getString(R.string.deselect_all)); } else { //If button text is Deselect All remove check from all items adapter.removeSelection(); //After checking all items change button text selectButton.setText(getResources().getString(R.string.select_all)); } } }); } } |
In all the three above Java classes the main thing that we need to focus is button click events:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
SparseBooleanArray selectedRows = adapter.getSelectedIds();//Get the selected ids from adapter //Check if item is selected or not via size if (selectedRows.size() > 0) { StringBuilder stringBuilder = new StringBuilder(); //Loop to all the selected rows array for (int i = 0; i < selectedRows.size(); i++) { //Check if selected rows have value i.e. checked item if (selectedRows.valueAt(i)) { //Get the checked item text from array list by getting keyAt method of selectedRowsarray String selectedRowLabel = arrayList.get(selectedRows.keyAt(i)); //append the row label text stringBuilder.append(selectedRowLabel + "\n"); } } Toast.makeText(context, "Selected Rows\n" + stringBuilder.toString(), Toast.LENGTH_SHORT).show(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
SparseBooleanArray selectedRows = adapter.getSelectedIds();//Get the selected ids from adapter //Check if item is selected or not via size if (selectedRows.size() > 0) { //Loop to all the selected rows array for (int i = (selectedRows.size() - 1); i >= 0; i--) { //Check if selected rows have value i.e. checked item if (selectedRows.valueAt(i)) { //remove the checked item arrayList.remove(selectedRows.keyAt(i)); } } //notify the adapter and remove all checked selection adapter.removeSelection(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
//Check the current text of Select Button if (selectButton.getText().toString().equals(getResources().getString(R.string.select_all))) { //If Text is Select All then loop to all array List items and check all of them for (int i = 0; i < arrayList.size(); i++) adapter.checkCheckBox(i, true); //After checking all items change button text selectButton.setText(getResources().getString(R.string.deselect_all)); } else { //If button text is Deselect All remove check from all items adapter.removeSelection(); //After checking all items change button text selectButton.setText(getResources().getString(R.string.select_all)); } |
7. Now after creating all fragment classes we have to create Adapters for ListView, GridView and RecyclerView.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
package com.listcheckbox_demo.adapter; import android.content.Context; import android.util.SparseBooleanArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import com.listcheckbox_demo.R; import java.util.ArrayList; /** * Created by sonu on 08/02/17. */ public class GridListAdapter extends BaseAdapter { private Context context; private ArrayList<String> arrayList; private LayoutInflater inflater; private boolean isListView; private SparseBooleanArray mSelectedItemsIds; public GridListAdapter(Context context, ArrayList<String> arrayList, boolean isListView) { this.context = context; this.arrayList = arrayList; this.isListView = isListView; inflater = LayoutInflater.from(context); mSelectedItemsIds = new SparseBooleanArray(); } @Override public int getCount() { return arrayList.size(); } @Override public Object getItem(int i) { return arrayList.get(i); } @Override public long getItemId(int i) { return i; } @Override public View getView(final int i, View view, ViewGroup viewGroup) { ViewHolder viewHolder; if (view == null) { viewHolder = new ViewHolder(); //inflate the layout on basis of boolean if (isListView) view = inflater.inflate(R.layout.list_custom_row_layout, viewGroup, false); else view = inflater.inflate(R.layout.grid_custom_row_layout, viewGroup, false); viewHolder.label = (TextView) view.findViewById(R.id.label); viewHolder.checkBox = (CheckBox) view.findViewById(R.id.checkbox); view.setTag(viewHolder); } else viewHolder = (ViewHolder) view.getTag(); viewHolder.label.setText(arrayList.get(i)); viewHolder.checkBox.setChecked(mSelectedItemsIds.get(i)); viewHolder.checkBox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { checkCheckBox(i, !mSelectedItemsIds.get(i)); } }); viewHolder.label.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { checkCheckBox(i, !mSelectedItemsIds.get(i)); } }); return view; } private class ViewHolder { private TextView label; private CheckBox checkBox; } /** * Remove all checkbox Selection **/ public void removeSelection() { mSelectedItemsIds = new SparseBooleanArray(); notifyDataSetChanged(); } /** * Check the Checkbox if not checked **/ public void checkCheckBox(int position, boolean value) { if (value) mSelectedItemsIds.put(position, true); else mSelectedItemsIds.delete(position); notifyDataSetChanged(); } /** * Return the selected Checkbox IDs **/ public SparseBooleanArray getSelectedIds() { return mSelectedItemsIds; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
package com.listcheckbox_demo.adapter; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.util.SparseBooleanArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.TextView; import com.listcheckbox_demo.R; import java.util.ArrayList; /** * Created by sonu on 19/09/16. */ public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.RecyclerViewHolder> { static class RecyclerViewHolder extends RecyclerView.ViewHolder { private TextView label; private CheckBox checkBox; RecyclerViewHolder(View view) { super(view); label = (TextView) view.findViewById(R.id.label); checkBox = (CheckBox) view.findViewById(R.id.checkbox); } } private ArrayList<String> arrayList; private Context context; private SparseBooleanArray mSelectedItemsIds; public RecyclerViewAdapter(Context context, ArrayList<String> arrayList) { this.arrayList = arrayList; this.context = context; mSelectedItemsIds = new SparseBooleanArray(); } @Override public RecyclerViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_custom_row_layout, viewGroup, false); return new RecyclerViewHolder(v); } @Override public void onBindViewHolder(final RecyclerViewHolder holder, final int i) { holder.label.setText(arrayList.get(i)); holder.checkBox.setChecked(mSelectedItemsIds.get(i)); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { checkCheckBox(i, !mSelectedItemsIds.get(i)); } }); holder.label.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { checkCheckBox(i, !mSelectedItemsIds.get(i)); } }); } @Override public int getItemCount() { return (null != arrayList ? arrayList.size() : 0); } /** * Remove all checkbox Selection **/ public void removeSelection() { mSelectedItemsIds = new SparseBooleanArray(); notifyDataSetChanged(); } /** * Check the Checkbox if not checked **/ public void checkCheckBox(int position, boolean value) { if (value) mSelectedItemsIds.put(position, true); else mSelectedItemsIds.delete(position); notifyDataSetChanged(); } /** * Return the selected Checkbox IDs **/ public SparseBooleanArray getSelectedIds() { return mSelectedItemsIds; } } |
In both the above adapter the common code is to select rows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/** * Remove all checkbox Selection **/ public void removeSelection() { mSelectedItemsIds = new SparseBooleanArray(); notifyDataSetChanged(); } /** * Check the Checkbox if not checked **/ public void checkCheckBox(int position, boolean value) { if (value) mSelectedItemsIds.put(position, true); else mSelectedItemsIds.delete(position); notifyDataSetChanged(); } /** * Return the selected Checkbox IDs **/ public SparseBooleanArray getSelectedIds() { return mSelectedItemsIds; } |
8. Finally all things done. Now you can also make your any type of multiple choice list view.
Thanks. 🙂
Subscribe to us and get the latest news.
13 Comments
nadia
Thursday, February 1st, 2018Hi nice work
i have the same work to do ,
me i used database SQLITE , so i have table product(id_product, name_product, image_product, namecategory) so in my first interface “fragment” i choos my category with image_category “the image it will be stock in drawable” and after when i click in one category like fruit so one spinner”listProduct” it will be open with the list of fruit i can do multi check for some product i want and i valide so when i valide it will stock in table and show in another fragment name “list”. So my problem that what is the solution should used after valide to return choose another category like vegetables and i click in image so interface “listProduct” it will be open again but with list of vegetables i check what i want like potato,peas and i valide so this list of Vegetables it will be add to list of fruits and when i click show list i can see the finally list , How can do it ?? The greate solution hope can help me thanks
Néstor
Thursday, July 12th, 2018How to catch the Item Click inside Fragment?
Dr. Droid
Friday, July 13th, 2018Hi Nestor,
Item click inside Fragment will be implemented same like we do in Activity.
Thanks
Néstor
Friday, July 13th, 2018Good, I am just trying to do it but seems not work. The setOnItemClickListener is not firing.
Dr. Droid
Saturday, July 14th, 2018Hi Nestor,
Can you share your code that you are trying to do at my Email Id : [email protected].
Thanks
Obie
Thursday, October 25th, 2018Hi, I’ve got issue .. i’ve implement your code into my code..
In my code, assume I have database List 100 array data in my checkbox list [0, 1, 2, 3, 4, 5……100]. after that I am check it in [2,4,5].. when debug I am just get value [2,4] .. it mean I didn’t get value of 5. can you help me please?\
thank you
Dr. Droid
Thursday, October 25th, 2018Hi Obie,
Can you check your code that 5th number item is checked or not? And if checked use some other cases like checking more items and debug and check if you are getting checked ones or not?
If still the issue is there then mail me your code/classes ay mail id. You can find it on the top of the blog.
Thanks
LyonOconner
Monday, January 28th, 2019there has to be a easier way, rigth ? is many code for simple checkbox in a gridview :c
Dr. Droid
Tuesday, January 29th, 2019Hi Lyon,
The code contains Listview, gridview and recyclerview example. May be due to that you feeling it’s too many code.
And also for listview and gridview I am using same code.
Thanks
Lyon
Monday, January 28th, 2019You can update this sample at Android 3.3 pls ????
Dr. Droid
Tuesday, January 29th, 2019Hi Lyon,
What issue you are facing in current code?
Thanks
Charlotte
Thursday, September 10th, 2020hello, can we put a checkbox in a cardview from a recyclerView ? I need to save items selected (name of room) from a postgresql and i have made a cardview. Can i make a filter of this witch checkbox ? thank you
Dr. Droid
Wednesday, September 16th, 2020Hi Charlotte,
Yes, it’s possible and you can do it, Just need to add extra filter logic.
Thanks