Note that there are some explanatory texts on larger screens.

plurals
  1. POManage buttons in ListView to show/hide a part
    primarykey
    data
    text
    <p>I have a <code>ListView</code> with <code>Button</code>'s. I want to hide the item that is visible when I click a <code>Button</code> from second item.</p> <p><img src="https://i.stack.imgur.com/TyTCr.png" alt="enter image description here"></p> <p>If I click the button "1" , I want to hide the blue "layout". I can manage the layouts if the click is made it the same item , but when I click a button from another item the layout´s are still visible. How can I manage to set the visibility for those items?</p> <p>This is may code. My LISTADAPTER </p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { final String item = items.get(position); View v = null; if (convertView != null) v = convertView; else v = inflater.inflate(R.layout.item, parent, false); TextView itemTV = (TextView) v.findViewById(R.id.item); itemTV.setText(item); final ImageView number1 = (ImageView) v.findViewById(R.id.number1); final ImageView number2 = (ImageView) v.findViewById(R.id.number2); final ImageView button1 = (ImageView) v.findViewById(R.id.button1); final ImageView button2 = (ImageView) v.findViewById(R.id.button2); final RelativeLayout blue = (RelativeLayout) v.findViewById(R.id.blue); final RelativeLayout green = (RelativeLayout) v .findViewById(R.id.green); blue.setVisibility(RelativeLayout.GONE); green.setVisibility(RelativeLayout.GONE); button1.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (on == 0) //show hide ---int on=0; { blue.setVisibility(RelativeLayout.VISIBLE); green.setVisibility(RelativeLayout.GONE); on = 1; Toast.makeText(context, "ImageButton clicked" + item, Toast.LENGTH_SHORT).show(); number1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast.makeText(context, "CLICK" + item, Toast.LENGTH_SHORT).show(); } }); number2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast.makeText(context, "ClICK" + item, Toast.LENGTH_SHORT).show(); } }); }// on equals 0 else { on = 0; blue.setVisibility(RelativeLayout.GONE); green.setVisibility(RelativeLayout.GONE); } } }); button2.setOnClickListener(new OnClickListener() { public void onClick(View v) { blue.setVisibility(RelativeLayout.GONE); green.setVisibility(RelativeLayout.VISIBLE); Toast.makeText(context, "CLICK" + item, Toast.LENGTH_SHORT).show(); number2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast.makeText(context, "CLICK" + item, Toast.LENGTH_SHORT).show(); } }); } }); return v; } </code></pre> <p>My ACTIVITY</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list); ListView lv = (ListView) findViewById( R.id.list ); lv.setOnItemClickListener( new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; arg0, android.view.View arg1, int arg2, long arg3) { Toast.makeText( ListImageButton.this, "List item clicked", Toast.LENGTH_SHORT).show(); } }); ArrayList&lt;String&gt; items = new ArrayList&lt;String&gt;(); items.add( "item1"); items.add( "item2"); items.add( "item3"); ListAdapter adapter = new ListAdapter( this, items); lv.setAdapter( adapter ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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