I need to create a layout with three Button and three ListView,when i click on first Button first Listview should be shown in the same activity and second button second ListView so on....
How is this possible?.Can anyone help me.
Have you considered using a Tab Layout? It's easy to use and you can have three tabs showing your list views, independently.
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
Add all of them to the same activity, then set the content of the three listviews. Add onClickListener() to each button and use View.Gone and View.Visible to control the visibility of the three ListViews. Or, like Hussain pointed out, just change the content of the single ListView
http://developer.android.com/reference/android/view/View.html#GONE
Related
I am making an android application.I have ListView in it which contains four rows having textView i.e
Hide
Unhide
Add Users
Delete users
I want to add ToggleButton in ListView for first two rows but don n't want to show it for other rows. How can i customize my ListView in this way.
Any help will be appreciated
You have to write a custom BaseAdapter. There you have the method getView() that is called for each listItem, so this is the right palce to define the layout of the listItems.
Please look at this article to ensure a smooth scrolling of your list.
And you can find a good Tutorial on Vogellas site.
If you want to add toggle button for first two rows only and not for all rows then one easy thing you can do is add in the custom listview layout file both the textview and toggle button but while implementing add (null) in the toggle button's place in the adapter for the rows for which you don't want the toggle button...
This is my first project in android and I want to display something like this in list view
Any advice is appreciated
You can go through CustomListView example.it can be done easily.
Please go through the Link below
how to customize listview row android
For achieving this layout you should use custom listview for that like it.
A row with one text view and four button mean five object in each row but show only two object one is textview and another is one button out or four button.
If you want to display fourth button then invisible first there button and fourth button in visible state.
If you want to display second button then first, third and fourth button invisible state only second button in visible state.
Fallow this logic in each row.
I hope you got you answer after using this logic.
My problem come from ListView. Without Buttons, the .setOnItemClickListener of the ListView work well. (start an Activity)
At time that I add Buttons into items of the ListView, Buttons are clickable but the items aren't more clickable...
I try to use myListView.setItemCanFocus(true); but it don't work...
Remove the focusable attribute from the Button would solve this problem. You could do that either in a layout xml file or java source code.
And one more tip, if you are using ImageButton instead of Button, you need setFocusable in your java code to make that work, cause the constructor of ImageButton would enabe this attribute after inflate from xml file.
It might be better to use an onTouch() callback for the clickable button within the listview. You should then be able to click.on both the list item and the button. See this question for some code (no need for touchDelegate).
The reason is button in your listview absorbs the onItemClickEvent.
A well explained tutorial is here
You can use this in .setOnItemClickListener of the ListView
view.findViewById(R.id.btn_id).setOnClickListener(new View.OnClickListener(){//your method})
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.
I have an activity that calls the
new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
I would like to add a button to the notes_row.xml that displays at the bottom of the screen "on top of" the actual notes_row allowing the user to still scroll through the list but hit the button if they want. Every time I try to change the layout of notes_row, I get the button on each item in the list. I am pretty new to Android and I think I need to inflate the button somehow so that it is layered in front of the list but doesn't impede the list, how do I go about doing that?
The R.layout.notes_row is the layout for each individual row. You will need to create a custom ListView.
Here is a tutorial: http://www.androidpeople.com/android-custom-listview-tutorial-example/
It sounds like you are adding the button to the notes_row layout. That will add it to each row.
Instead, you want to add it to the layout for the Activity. Are you extending from ListActivity? You could try adding the button as a footer to the ListView.
Otherwise, you can extend from a standard Activity and supply a layout file for that activity that includes a ListView and a Button. If you haven't yet, read through declaring layout and common layout objects to get a start on creating a layout.
If you will try to edit notes_row.xml file and add a button there it will come in each row, what you can do .. try editing the xml for the parent activity where you are trying to put you list view. In that xml you can easily put a button at the bottom