Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to create a Custom Array Adapter and all set.</p> <p>Here is the Activity Class I created for ListView for ChekBoxList</p> <p><strong>ActivityGamesList.java</strong></p> <pre><code>package com.rdc.gameListApp; import java.util.List; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.CheckBox; import android.widget.ListView; import android.widget.Toast; public class ActivityGamesList extends Activity { private ListView listGames = null; private DBAdapter database = null; private Context context = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_of_games); final CheckBox favBox = (CheckBox) findViewById(R.id.favbuttonInList); listGames = (ListView) findViewById(R.id.listViewGame); context = getApplicationContext(); database = new DBAdapter(context); //here I am getting the data from database and putting in to List List&lt;String&gt; gamelistArrayR = database.selectAllName(); // custom adapter for adding fav box //make sure here "gamelistArrayR" is List and type is String listGames.setAdapter(new CustomAdapter(this, gamelistArrayR)); //listener for list view listGames.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { Toast.makeText(getApplicationContext(), "You have selected: " + position+" no row", Toast.LENGTH_SHORT).show(); } }); } } </code></pre> <p>and below is the Custom Array Adapter</p> <p><strong>CustomAdapter.java</strong></p> <hr> <pre><code>package com.rdc.gameListApp; import java.util.List; import android.content.Context; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.TextView; import android.widget.Toast; public class CustomAdapter extends ArrayAdapter&lt;String&gt; { private final Context context; private final List&lt;String&gt; values; public CustomAdapter(Context context, List&lt;String&gt; gamelistArrayR) { super(context, R.layout.list_row_custom, gamelistArrayR); this.context = context; this.values = gamelistArrayR; } @Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.list_row_custom, parent, false); //Game Name Text in list TextView textView = (TextView) rowView.findViewById(R.id.txtGameNameInList); // Check Box in list CheckBox favBox = (CheckBox) rowView.findViewById(R.id.favbuttonInList); textView.setText(values.get(position)); //listener for check box favBox .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) { Boolean flag = isChecked; if(flag){ Log.v("Debug", "step no 1"); Toast.makeText(context, "Marked as Favorite Game!", 1).show(); } } }); return rowView; } } </code></pre> <p>and i got the output like this way..</p> <p><img src="https://i.stack.imgur.com/D7UwO.jpg" alt="enter image description here"></p> <p><strong>Edit:</strong></p> <p>When you scroll list, the chekboxrs gets uncheked because or recreate view.</p> <p>so you need to store the state of checkbox for that you should check below links</p> <p><a href="https://stackoverflow.com/questions/9309250/checkbox-gets-unchecked-on-scroll-in-a-custom-listview"><strong>this</strong></a> So thread or <a href="http://www.lalit3686.blogspot.in/2012/06/today-i-am-going-to-show-how-to-deal.html" rel="nofollow noreferrer"><strong>this</strong></a> tutorial</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload