add subitem to listview item after clicking an item - android

I am working on an android application that I like to do something like this picture below to a listview:
as you can see, there's a custom adapter for a list view that generates a list out of one of my classes.
I want to add a view like a Linearlayout or something under a Listview item after I clicked it.
how can I do that?
PS: where I have to put an onItemClickListener()? in my adapter's class or in my main page after onCreate() method?
PPS: in the picture, I meant SUBITEM FOR ITEM1... sorry...

You essentially want to do what this person does with a ViewStub, and implement an OnClickListener that is attached to each ListItem.
Please let me know if that is not clear or if you can't find a good example, and I'll see what I can do. :)

Related

Alternate for a listview with single row

I have a ImageView with a TextView and Button. I have it currently in a custom list view, but I noticed now that I don't need to show more as one element (object). So I actually don't need a Listview to show the row (list entry). How can I show the list entry without a Listview?
You can put the elements of your custom listview item into a Layout, e.g. LinearLayout and simply add it to your activity's layout where you needed it.
You can set an OnClickListener for that layout, so user can click the whole thing.
I think you should use ListActivity. Then you can set up empty view for list. Here some tutorial: ListActivity and ListView Tips.
Also you can implement that logic with Recycler view by yourself or use library.
Here is solution from stackoverflow

Change imageview for selected item in listview

In my layout I have a button and a listview. How can I change the imageview of item I selected when the button is clicked. So lets say, I select 5 items, and after I click the button, images for those 5 items will be changed.
So I am confused what function I should use. Right now i used button.setOnClickListener but it seems wrong because only the very first item's imageview will be changed when button clicked. Should I use listview.setItemOnClickListener? Or is there any other way I can do this?
Thanks a lot!
Add a boolean to the data object in your adapter. Say you've got ArrayAdapter<MyDataObject>. Add some kind of "selected" field in the MyDataObject, and toggle it when you "select" the row.
Override getView in the adapter (you'll need a custom Adapter, btw. I'd just extend ArrayAdapter). When you render the row, if the "selected" field is true, show the "other" image.
When you click the button, call 'notifyDataSetChanged' on the adapter. The will cause the visible rows to refresh themselves (and call getView for each).
I think that'll work.
Since you only want images to change when you click the button, you'll need to have some kind of global boolean, so the getView won't show the image until the button has been clicked.
The complication here is, you have to deal with rows that may have been scrolled out of view, which don't have active views, but logically exist. It would be really hard to explain the concept here. I'd suggest some tutorials on ListView if you're not familiar with the recycling of row views.
You can used custom baseadapter for listview and setonclicklistener in the getView() method.... see tutorial here this is hope for help
You can use button click listener as well as on itemClickListener too but to make a image view in selected state in a list, you have to call setSelected method of imageview parent layout.
Please put a comment if you don't get me.
Thanks

Custom Listener for a ListView item

I have a View with a ListView appended, which actually uses a custom view item done programatically. Inside each list item I have a button which I need to track, to update another item in the view. It is only invalidated when you click on the list item button, not anywhere else in the list item.
So I thought of creating a custom Listener. I trigger it when the button is clicked, but I have no way to access it from the ListView activity.
Is there a way to simulate those setOnItem...Listener's using a custom listener? Thanks in advance
Please see this link to help with how to set onClickListener from within custom ListAdapters.
You can use the myButton.getTag() and myButton.setTag() to put and get data to/from your View/Button.
See this link as well to help with custom ListAdapters.
Here is another good example I found of how to use a custom adapter.

ListView clicklisteners

I have a list view which has a couple of views within it, I have a textView and an ImageView.
What I need to do is, I want a person to be able to click just on the imageView without causing the onItemClicked function to be invoked, If the person clicks the ImageView, it should do something else, but if the person clicks away(apart from the imageview) from the imageView, then the onItemClicked is fired.
How do I do this?
It is kinda like, the listView on the android phone callLogs whereby, the green phone icon is somehow separated from the list but when clicked, it should know which listItem was selected and act accordingly.
I will appreciate the help. Thanks.
Here are some links for you are looking for. Advanced but if you stick with it and dont give up on this, you will learn a ton!!! Take a look:
Android: ListView elements with multiple clickable buttons
Android custom list item with nested widgets
use holder.imageView.setOnClickListener() in getView() method of adapter class.

android listview

I have created one list view.. it is having 5 items...
Now I want split the list items...
when user clickon the first listitem or focus on first item then immediately it has to show followed some text views or other things..but it has to show same list..
and agian same when he clickon or focus on the second item that first item has to be close and second item has to act some thing....
I think you need to implement the concept of "Expandable Listview", so that the clicking on one item, it will be expanded with their sub-items.
Refer the android-sdk page of Expandable ListView: http://developer.android.com/reference/android/widget/ExpandableListView.html
For having an example, check this site: http://mylifewithandroid.blogspot.com/2008/05/expandable-lists.html
Pls, check the below image, do you want to perform as same ????
If you want to do the same, it is already given in the "API-Demos" at Views/Expandable Lists/1. Custom Adapter.
Enjoy !!
The problem is that you cannot use the standard ListView in your case, because in the standard ListView, the View of each row has to be one TextView.
In your case, you need it to be at least two TextViews (The standard Text, and the one that's gonna show up onClick/onFocus).
You have to create your custom ListAdapter, and override the getView() function.
Here is a code snippet that shows how to do it properly:
Custom Adapter
In the getView(), you have to inflate the XML file that describes your List Row, and return it.
In your case, I believe your XML file should contain 2 TextViews, one visible and one invisible.
Then, to handle the clicks, you can set a onItemClickListener on your ListView in your Activity class.
The best way may be to have your Activity class implementing onItemClickListener, and to use this onItemClickListener to handle those.
In the onClick() function, you just have to set the Visibility of your hidden TextView to VISIBLE.
You need to build custom rows, and handle showing more text on each row, there is no easy magicall way of doing it, but inflating your own rows, and setting a couple of attributes visibility isnt all that hard either.

Categories

Resources