Search code examples
androidlistviewandroid-listviewonclick

Android how to show hidden item only for one row on click


im trying to create a listView, that has an Button item on it. I want to make this button clickable, so I did something like this code in Adapter, getView:

myButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("_myButton_Log", "ShowOnClick");
            }
        });

And now im trying to change the visibility parameter for my textView:

TextView myDesc = row.findViewById(R.id.my_desc);
myDesc.setVisibility(convertView.GONE);

I want to show this textView in only one row, after click this button.

Now I make that, the button is clickable for each rows but as you can see it's show only the Log. Im a newbie in the ListViews and buttons on it and im trying to get knowledge how to make it work, but for now I cannot find any help...

So im begging here for some help! :)

Anyway if you want me to use the OnItemClickListener it's not possible because im using it for another way.


Solution

  • Ok I found out an response for my question.

    Everyone with this problem - just need to make a simple action for a button in list view in your adapter like:

    myButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
    
            TextView myPrice = row.findViewById(R.id.price);
            Button myButton = row.findViewById(R.id.button);
    
            myPrice.setVisibility(convertView.VISIBLE);
            myButton.setVisibility(convertView.GONE);
        }
    });