Efficient way to display details of list item - android

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.

Related

Android. RecyclerView with collapsing items

I need to create recyclerView with collapsing items. For example, I have a list of 10 items. By default, I only need to flip the first 2 elements. But by clicking on the "See all" button, I need to display all the items in the list. And vice versa, by clicking on the "Hide" button, you need to leave only the first two items in the list. Here is an example:
I suppose to implement it like this: create a flag that determines whether the full list is displayed or not, and by clicking on the button, depending on the flag, send the full list to the adapter or cut it to two elements and call notifyDataSetChanged().
But this solution seemed to me not very good, perhaps there is a more elegant solution.
Note: I don't need nested collapsing elements. I just need to display two items from a list or all items.
Please help me.

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.

how to keep check box selection in ListView

I have created a custom ListView.. every element of my ListView constructing from a layout.
My layout will have some TextViews and a ToggleButton. My ListView will have some 50 elemnts and my device screen can show 2 elements at a time.
Now if we select ToggleButton on a Item and scroll down my ListView , the selected item will be out of screen and when I come back to the previous selected item I am observinf that selection for that toggle button is gone.
I know that this is a normal behavior in android that It will construct the elements which is currently displaying.
But I want to keep that value.. Is there any way that we preserve selection. or can I tell ListView to donot construct every time.. memory is a not a issue for my application.
Please let me know if there's any good solution for this.
You could store the states of the checkbox in a map with the position as the key. So whenever the list reloads after scroll, it loads based on the hashmap state. You should write this logic in the getView()

loading listview twice?

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.

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