Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, this may not perfectly answer your question but I had done something sort of similar. Basically, I added items to a table and needed to have a remove button associated with the item. When the remove button was clicked, it needed to remove only that item from the table. This could be adapted to your needs so rather than removing the item clicked, it finds the previous item, unclicks it, and then highlights then newly clicked one. </p> <p>So what I did was give a tag to the buttons themselves (obviously they need to be unique). When a button is clicked, save its tag in something like a sharedPreference for later reference. Then when a new button is clicked, simply find the button with the previously clicked tag and unmark the row that it is in and then mark the row for the newly clicked button. Here is the code I used (sorry the variable names are terrible, I actually had this working in a test app that was never released so I didn't bother giving them better names):</p> <pre><code> //Previous button clicked String id = &lt;get this from wherever you choose to store it&gt; // create a new TableRow TableRow row = new TableRow(getApplicationContext()); TextView t = new TextView(getApplicationContext()); t.setTextColor(Color.BLACK); t.setText(unique); Button b = new Button(getApplicationContext()); b.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { for(int i = 0; i &lt; table.getChildCount(); i++) { TableRow row = (TableRow) table.getChildAt(i); Button bt = (Button) row.getChildAt(1); TextView view = (TextView)row.getChildAt(0); if( id.equals(v.getTag())) //they match, so this is the button that was previously clicked { //Put your code here to unclick the previous button and mark the new one as clicked. } } } }); b.setText(R.string.removeButtonText); b.setTag(t.getText().toString()); /***BE SURE TO SAVE THE NEW BUTTON TAG (t.getText().toString()) SOMEWHERE LIKE A SHARED PREFERENCE****/ //saving the tag //add the row to the table row.addView(t); row.addView(b); // add the TableRow to the TableLayout table.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); </code></pre> <p>Again, I don't suspect this is the exact answer you are looking for, but maybe it will give you an idea to try out. Hopefully this makes some sense, if not please feel free to ask for clarification. Sorry if it is way off base as well.</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