how to show and hide buttons in listView - android

As shown in the image when I click on an item in the list view. Buttons show up.
I want to hide buttons when I click on different items and show on current clicked item.
How can I make it work?

Need to preserve view into a variable like prevView. and then click on another item.
Check whether prevView is null or not. If not null. then get button id .
e.g. prevView.findViewById();
and Make their visibility.GONE. and also null prevView.
I hope this will help you.

You can achieve this by making a model class.
take variable for particular buttons in Model. after clicking on a different item set true/false tag in the model and show/hide view according to that tag.

You should be using an expandable ListView so that you can get the buttons shown when you tap on the list item and it get closed when you tap on the other item in the list.

Related

Verify if there are any selected items in a gridview

im developing an app and implementing an onboarding to ask the user to select certain options that will be displayed in a grid view. I want the user to select and unselect and item for this im using a simple toggleSelected(){selected=!selected} declared in my item entry class.
I also have a button at the bottom that will be disabled if all the items in the gridview have isSelected() = false. What is the best way to check this?
Thanks for the help
In the model class which actually contains the data,the list which you provide to the adapter of the recyclerView , add a variable isSelected and set its default value to false, whenever a grid item gets selected, set it to true and when it gets unselected, set it to false. In this way you could travel that list and then know which all are selected and which are not.
One way would be to loop over all the elements and check if any is selected.
But that would be quite resource heavy.
I'd rather suggest that you keep a count of selected elements.
If count != 0, then enable your button.

Change text of one specific context menu item

I've created a context menu for my recycler view items. In the menu I have Watch (like favourites), Share and Hide. Now what I want to do is get the specific position of the Recycler View and check if the Watch or Hide button has been pressed. How can I go about doing this? I've used a flag but that just checks the whole Recycler View so that doesn't work.
I can show source code on request too. I know it needs to go in my Adapter but can't figure out the position of it
Thanks in advance.
just add a boolean variable in your List to check whether to show Watch or Hide button.
use getAdapterPosition() method when user clicked the clicked on button and then use that position to update value in your model class.

Android: Show Listview when clicking on EditText

I don't know if this is the right method but I would like to know if is it possible to show a Listview when the user clicks on an EditText/TextView and show afterwards the selected item text in this EditText. I know how to declare the EditText in the layout but is there any example of when clicking on the listener show the ListView? Do I need to add this Listview in the XML layout or do I have to add it programatically?
Thank you
if your app wants to have a sort of text viewand when you click on it you need to show up a list view then you can use expandable list view check this tutorial
http://theopentutorials.com/tutorials/android/listview/android-expandable-list-view-example/
Sorry, a I was looking just for a Spinner, I thought that it was another type of ListView

Clicking List-view row and child Button as well

My ListView's row has one Button. Now i want to set click event to both row and button. But as i know ListView loose its onItemClick property if we set it's child click event. So please guide me a way to doing both at once
If you are using Buttons inside each list item, then set the click listener for the buttons on not on the list item.
Button.setOnClickListener(View.OnClickListener)
The list item clicks should go ignored and the buttons click listeners should do what you want.
You have to use ListView.setOnItemClickListener(OnItemClickListener). See the tutorial.
In OnItemClickListener.onItemClick() you're provided with the position of the item.
I don't understand why you don't want to use ListView.setOnItemClickListener(OnItemClickListener) ?
Because it react instantly to a touch event. Isn't what you want?

How to display "More" list item in ListView?

I want to display a list item that says "More" at the end of my ListView. Clicking on this list-item will perform some action. How can I create this "more" list item?
I don't know about the "Clicking on this list-item will perform some action" part. The typical pattern is that once the user scrolls to the bottom, new material is loaded automatically. Some people do that by detecting the scroll. I do it by putting in a "More" placeholder and detecting when that is used. Here is a component that implements this pattern.
Just add another value to your arrayadapter (or any other adapter), you might be using.set the text to 'more' .
Suppose you have n items in the list then handle the (n+1)th postion click and do your stuff.
You can add a footer to your listview...
Did you check this post out?
Android ListView Footer View not being placed on the bottom of the screen

Categories

Resources