I want to show an image in start or end of the TextView
on when I click it. The TextView
is in the ListView
.
For and example I have attached an image below.
an example of what I want
I need that when I clicked on any text, a checkmark appeared next to the text. In the example with the picture, I showed text 3 with a check mark.
After all this, when the checkmark is in the right place (where it was clicked). I click the submit button and it sends me to another page with a checkmarked text. the example was text 3.
Please help me to do this. I will be glad for any help. Thanks!
CodePudding user response:
There are two way to achieve this goal.
- Use
RecyclerView
- Use
CustomAdapter
You can hide and show that Tick on click on Item.
There are multiple tutorials:
Recyclerview Tutorial: https://youtu.be/ob8HyqHMr54
ListView Tutorial: http://android-er.blogspot.com/2010/06/using-convertview-in-getview-to-make.html
CodePudding user response:
I've implemented an easy way for your task / issue
Assume you've used RecyclerView
Do change in onBindViewHolder
I've used ImageView for check icon
int selectedindex = 0; @Override public void onBindViewHolder(MyViewHolder holder, final int position) { holder.YourView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { selectedindex = position; notifyDataSetChanged(); } }); if(selectedindex == position) holder.ivCheck.setVisibility(Visibility.VISIBLE); else holder.ivCheck.setVisibility(Visibility.GONE); }
CodePudding user response:
you can use RecyclerView instead of ListView. You can place an ImageView in the Item made recyclerView which you can hide and display based on the click on the RecycelerView Item.