i am trying to develop this app in android that has 3-4 buttons and a list being displayed below them. each button when clicked must reload the list with new contents based on which button was clicked.
each row in the list has a picture and two lines of text.
could some one please suggest me how do I perform the reloading part.
Attach the new adapter, with updated elements, with the listView, it will work as reloading the list view......
You could grab the list, in whatever layout it is in (ex LinearLayout) by doing a:
LinearLayout ll = (LinearLayout)getViewById(R.id.thislayout)
Remove the elements from the list as you desire using:
ll.removeView(view);
edit the view object as you want (changing the source etc) then re-add it to the LinearLayout using:
ll.addView(view);
Related
I created a player list program, now according to the program I created, there is a button (at start_activity) when the program starts. clicking on this button will open a list created by the next "recyclerview". I have a question about how to put two buttons (to "start_activity") ("new stars" and "historical stars") and connect both to one recyclerview, the list design will be the same for both, only the names in the list will change . is it possible to use the same recyclerview for both to make it much simpler? how please show an example from the code. Thank you.
It's simple.
On first button click - get your list data & set an adapter in a recyclerview.
On second button click - get your other list data & set an adapter in the same recyclerview.
So your data will be updated. You just have to initialize new data & adapter on button click, then set adapter in the recyclerview.
Screenshot of the App
I have a DeviceLayout.xml file which has a list of buttons in a grid as shown below. I used to pull it using an include tag in the MainLayout.
No activity is defined for DeviceLayout. Just xml file.
Now, the devices in the image are statically added. I want to make the button creation dynamic. If user clicks the "Add Device" Button, a new popup has to come up asking the details of the Device and it should be displayed on the home.
Please help. No idea how to do this.
First, in your activity you should use an adapter to populate the gridview.
Then, make your activity pass the dataset to be displayed to the gridview dynamically.
After adding a new device in your dataset, just update the grid ( you can use a adapter's notifydatasetchanged method).
I need help regarding adding new set of views and get value from those views.
In my example, I want to add 4 TextViews on Button click and open TimePicker from each view click and display new selected time on respective TextView.
Below is screenshot of view.
If these 4 views are fixed you could just create the xml and add them all to a single holder that you set invisible. If you mean by dynamic that it could be either 4 or 99 views, I'd recommend a RecyclerView. Plenty of examples on the internet. If you create a recyclerview with a custom adapter it is very easy to get the respective data per view.
For the future, please add more context to your question like what you've tried, what the result was and why this isn't your expected result. This is a very broad question.
Assuming that on clicking the clock button under the time section (on the right) you would want to set the selected time into the text field. You can simply call view.getParent() on click of the button and from the parent you can get the first child i.e child at 0 and set the text into the text field. This will work provided the button and textfield are within the same layout.
I'm building an android app and I'm trying to replace a list view with another list view if you click a button, like the notifications page on Instagram. On that page, if you click on the top "following" button it will show you a listview of what your followers have liked. If you click on the "you" button it will show you a listview of what people have liked your photos.
Any help would be greatly appreciated!
You can do it by following ways,
1. add Two listviews and can change the visibility as per your requirement.
2. On button click you can load the other data into same list view and can update your adapter in the same list view.
in 1 you have to load two list view at first which will consume more time if data is larger sure you can write a login in asynctask to load list views in background thread.
in 2 you have to update your adapter at the button so you will have to provide some progress bar of dialog for user while you list view is getting update.
You can use either of this whichever suites you best.
Simply , You don't need to switch Listview , you only need to switch adapters .
eg, you can switch to mFollowingAdapter when clicked on Following button and switch to mYouAdapter when you select "You" tab. that's it.
You should write a list, that has a custom adapter. This adapter will be able to display BOTH views you want to display.
If the data to be displayed is the same format (ie. both have an imageview next to a textview), you are in good shape.
When you want to switch to a different list, get the information you would like to display, replace the data in your the collection backing your list, then notify the list that the data has changed, and it should redraw.
So, this might look like:
create ArrayList() with data A
setup List, with this data and display
replace the ArrayList() with data B
call listView.notifyDataSetChanged
You can still do this if the Data A, and Data B have different views, in this case, you would need to handle this logic in your custom adapter.
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