loading listview twice? - android

I have an activity on the top of it there are some buttons from which when a button pressed it loads the dialog with country list and when user choose choose the country it will load the channel list below buttons.
so when activity start it shows blank screen until user choose the country
so i want to show a list when activity will start and then same procedure will follow as above.
but how can i load two different listview?
i tried
acivity start
load the default country channel's list
buttonclick listener
perform click {
load the another list
}
using the base adapter class found here.

Just switch adapter to current list (this is the easy way to do it)
OR
In your android xml file, where you create your activity, create two listviews with different ids. First listView will have android:visibility="visible" (this one will be shown first) and the second one will have android:visibility="gone"(you will make this visible when you perform the click).
When you want to switch the lists, just set first listview visibility to View.VISIBLE and the other one to View.GONE, from code.
Don't forget to switch adapters for different lists (this may be a bug source)

I would do following
Have a flag like isCountrySelected
Change your adapter and onitemclick handler so that according to isCountrySelected, you either load channel list or country list.

Related

single activity recyclerview for two button

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.

Android open ListView for multiple selection programmatically

I got a fragment with a ListView. The purpose of the list is simply checking items in that list, so I want to add something to the onCreateView method which will make the list enter its multiple selection mode automatically as the fragment shows, without the need for the user to long press an item. How can I do that?
to use longpress , you can do this way,
android:choiceMode="multipleChoiceModal"
or
setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL)
go through this for more information

Android: How to dynamically replace a list view with another list view like Instagram with onClick?

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.

Efficient way to display details of list item

I am working on app that is targeted to 7" or above tablets. So target platform is Android 3.x.
I am looking for an efficient approach to display details for list item when it is clicked. I have a list displayed with bunch of items. (Note: Due to the nature of the application I do not want to share ListView with other view or Fragment in this activity). When an item of list gets clicked I have to display details of that time. Details of an item take pretty much whole screen. I have couple of approach in mind:
Simplest one is : on List item clicked simply start an Activity that displays details of that item. But I guess it didn't seem efficient as every time item is clicked this Detail Activity is created and then destroyed.
Create a custom dialog for Detail of list item and hold its reference in List Activity. As soon as item is clicked show this dialog displaying contents corresponding to clicked list item. With this approach I would like Dialog to take complete screen (any suggestion appreciated).
Define FrameLayout in ListView with Visibility Gone (so that frame layout dont take any space in ListView screen). This frame layout act as a container for Details Fragment. As soon as list item is clicked hide ListView and make frame layout visible. With this approach I am not efficiently navigate back and forth between list view and details view.
Should come from an Android expert. :)
Thank you for your time.
There isn't any reason why you can't take approach 1 (create an Activity to display the details). Even better combine 1 & 2 to create an Activity with a dialog theme with something like this in the AndroidManifest.xml...
<activity
android:name=".DetailsActivity"
android:theme="#android:style/Theme.Dialog">
</activity>
Give the Activity a 'Close' button which when clicked, calls finish() to exit the Activity. I have several dialog-themed Activities in my current project and they work really well.

i want to make a screen with list and it should include a drill down concept in android app on gingerbread

My application should have an activity to show a list of elements. These elements can be selected using some checkbox mechanism AND if it is clicked another list on next screen with the sub elements should be shown.
Need desperate help.
link to snippet would be preferable. thanx.
Create two activities extending from ListActivity. Check this link to create a listActivity and implement click listener for list items and on click event start second activity...

Categories

Resources