Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can i get the total number of clicked position in toggle button "On"position if i click the update button in android using arraylist?
    text
    copied!<pre><code>public class MainActivity extends Activity { String[] countries = new String[] { "India", "Pakistan", "Sri Lanka", "China", "Bangladesh", "Nepal", "Afghanistan", "North Korea", "South Korea", "Japan" }; // Array of booleans to store toggle button status boolean[] status = { true, false, false, false, false, false, false, false, false, false }; int v1; ArrayList&lt;Integer&gt; intItems = new ArrayList&lt;Integer&gt;(); int pos; String sta; Button updatespot=(Button) findViewById(R.id.update); updatespot.setOnClickListener(new View.OnClickListener() { //abre setonclicklistener( @Override public void onClick(View v) { // final if(sta == "On" ) { intItems.add(v1); Toast.makeText(getBaseContext(), "position : " + intItems, Toast.LENGTH_SHORT).show(); } } }); GridView lvCountries = (GridView) findViewById(R.id.lv_countries); OnItemClickListener itemClickListener = new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; lv, View item, int position, long id) { GridView lView = (GridView) lv; SimpleAdapter adapter = (SimpleAdapter) lView.getAdapter(); HashMap&lt;String,Object&gt; hm = (HashMap) adapter.getItem(position); /** The clicked Item in the GridView */ FrameLayout rLayout = (FrameLayout) item; /** Getting the toggle button corresponding to the clicked item */ ToggleButton tgl = (ToggleButton) rLayout.getChildAt(1); String strStatus = ""; if(tgl.isChecked()){ tgl.setChecked(false); strStatus = "Off"; status[position]=false; }else{ tgl.setChecked(true); strStatus = "On"; sta=strStatus; status[position]=true; v1=position; // Toast.makeText(getBaseContext(), (String) hm.get("txt") + " : " + v1, Toast.LENGTH_SHORT).show(); } </code></pre> <p>I have the gridview image with toggle button.if i click the toggle button in "On"position,then how can i get the total number of clicked position in "On"position if i click the update button in android?</p>
 

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