Good day, dear. There is such a task. Display a ListView and in it in each element certain data with an ArrayList. But there is one nuance. By default (standard), each element is shown only half (it consists of 2 layouts for one of which is visibility = gone), and by clicking on this item it should be shown in full (for both layouts, visibility = visible), by clicking back again hide extra part. It is clear that I will create a custom adapter and stick the data into it, but how can I expand and collapse exactly the element to which I tap, and not the last one? Please tell me how to implement it.

enter image description here

Code:

@Override public View getView(int position, View convertView, ViewGroup parent) { // используем созданные, но не используемые view View view = inflater.inflate(R.layout.list_view_item, parent, false); Product p = getProduct(position); text1.setText(p.getName()); text2.setText(p.getLastName()); layoutParent.setOnClicListner(new OnClickListener() { @Override public void onClick(View v) { if(layiutTwo.getVisibiliti() == View.VISIBLE){ layiutTwo.setVisibiliti().View.GONE; } else { layiutTwo.setVisibiliti().View.VISIBLE; } } }); return view; } 
  • In the getView method of the adapter, hang click listeners on getView and change the visibility of individual elements. But it will have to remove the listeners of clicks hung on the adapter outside. - Yuriy SPb
  • Unfortunately this does not work. More precisely it does not work correctly. Thus, by the blade, the last is always revealed on any element. - Pavel Zlotarenchuk February
  • It definitely works. You just have a bug somewhere in the code. Show the code. - Yuriy SPb
  • one
    add boolean isSelected in the Product, change the p.isSelected property in the adapter by clicking and make it visible / invisible - ivansoft

0