Two Custom ListViews inside an activity for larger displays - android

Android 2.3.3
I have an activity where I display "Device's Contacts" in my custom view(imageview, 3 textboxes, checkbox) inside a ListView. What I want to do is, display two listviews with both showing alternate contacts (Splitting the listview into two) side by side. This is because, I want to utilize space on landscape mode of larger displays.
I haven't seen many questions on SO and somewhere I have read that, this approach will mess up scrolling of listviews and will get messy.
So, can someone explain why/how would it get messy and is there another way to use the space in larger displays in my scenario.
Thanks.

This sounds like exactly what the Building a Dynamic UI with Fragments android tutorial was designed to address.
As #ooops mentions you will need to put each ListView within its own container. In the tutorial I linked to, they accomplished this by using 2 Fragment instances, each that loaded different content. Whether you copy their example and use the <fragment> tab (admitidly I don't remember which API level that works on) or use a different container like a regular LinearLayout you should be able to acomplish this easily.

You could do this, but each ListView should be in it's own container.
For examlple How to use multiple listviews in a single activity on android?
But be aware that #Rarw is more correct in the way of good programming practice. Fragments are recommended for such purpose.

Related

Reducing layout views in an Activity for better performance

I have an activity with a scrollable view. I also have containers that all have the same structure - consist of imageButton and also several textViews that serve as a description. The whole thing looks like that:
The problem is that there are around 30 elements with the same structure and when each one of them has so many textViews I get the warning -
Layout has more than 80 views, bad for performance.
The reason why I have so many views is because of the different formatting of the different words. How would it be possible to reduce the views and still get the same formatting?
P.S. I already read that how to resolve "Layout has more than 80 views, bad for performance"? . But this doesn't help me, since all the information that I have, should be static and always visible.
You will want to set up your layout using a RecyclerView.
If your app needs to display a scrolling list of elements based on large data sets (or data that frequently changes), you should use RecyclerView.
Android Developer Guide has some pretty good documentation on how to set this up. Also, here is a video tutorial on RecyclerView by SlideNerd. He has a pretty good series for android developers.
In addition to what J. Jefferson said about RecyclerView. As you mentioned in your initial post:
The reason why I have so many views is because of the different
formatting of the different words. How would it be possible to reduce
the views and still get the same formatting?
You can do different text formatting without creating a separate textview. Have a look at the following https://stackoverflow.com/a/41953808/8312634

Correct design for using the same data for different views

I am new in the corporate world & from design perspective please correct me if I am doing something wrong here
I am fetching images from Flickr API.
GOAL: Show these images in two different type of view, grid view and listview. Which can be switch through the slide.
So I am using a View pager with two fragments and both of these fragments has separate listeners. So when the response came from Flickr both of these listeners are notified.
In my opinion, this saves two times calling of REST API, but I am looking for even more efficient design or flow through which
Using single listener
Rest API should be called once
Result should be store (Just in ArrayList) and share to both of views
May not choosing two separate fragments
Avoid creating Adapter object two times
Image should be stored in cache
Any tweak or suggestions will be helpful a lot, please comment if you don't understand any part or whole question.
For above problem, the tweaking you are thinking is almost right. Other than below:
What I believe you must create two different adapters to have more control over different views. For example, you might want to show with scale type crop center for an image in list view but scale type center inside for an image in grid view. There might be the different type of thing you may want to perform. So, it's a good practice to make two different adapters, to make the code more manageable.
Again the same goes for the fragment, see if actions in both the fragments are same or can be done with single variable passing. Then only go with a single fragment.
Rest of the things are perfect.

Should I create multiple hidden ListViews or just one and change the contents

So I have an activity that will display a list of options and when you click an option it should move to a list that displays the choices for that option, but I'd like both lists to be in the same activity.
I'm debating between the two options of using a single listview and changing the contents (maybe by swapping the adapter if that works, not sure) whenever a user navigates between the two lists, or using something like a viewswitcher where both lists exist independently, but only one is visible at a time.
I would definitely think the viewswitcher option would be the cleaner option, but how will it perform especially if I need to scale it to more than two lists? Is there much overhead to creating a listview that's not rendered?
Keeping one listview and switching out its backend would be a pain, especially considering all the re-initialization every single time you click an option.
-Use two ListFragments, have one control the other. Using Fragments instead of two separate ListActivities would mean that when you build a tablet interface, it would be minimal work to have one Activity with both on the same screen.
-Use an ExpandableListView
I did have a choice like that. I was using a list view to navigate to a remote webdav server.
At the beginning I was using one view for each folder. It was cool: using back was allowing me not to worry about navigation history.
But after a while, there was some cases where I needed to manage all the views at once, or kill them all or implement a communication between views (for parameters). And it was a nightmare to achieve. Also my list were beginning to be heavy and a lot of list in memory is never a good thing. I finally gave up and managed all the navigation in a unique list view. I should have do it at first.

Android tabs with views, still dynamic

I want to avoid using intents in android tabs. so I am doing views, but I would like an example on how a large project does this.
Mainly because I am not just displaying static information configured on the view xml, but I am pulling a lot of information from a server when a user interacts with a button within a view. The code seems like it can get really long and messy with this view implementation, instead of when each view is in a separate activity.
I would like to see how others separated their methods in a nice neat and organized way.
and that example hello-tabwidget is nowhere near what I am looking for, thanks
use a viewflipper. its like the text switcher. u put a layout inside of a viewflipper and trigger it wen a tab is selected.
http://www.warriorpoint.com/blog/2009/05/26/android-switching-screens-in-an-activity-with-animations-using-viewflipper/

Android: using viewfliper with dynamic no of slides, number of slides can vary

I need to implement an application which uses a sliding view (ViewFlipper) for one of its activity, this activity displays information stored on and array and passed from the previous activity via intent. The number of slides or tabs is expected to vary depending on the number of elements in the array. i.e for 4 elements in the array,we shall get 4 slides and when there is only 3, we have the same amount of slides displaying respective information accordingly.
Any idea on how to implement this, an example if possible? I am very new to android development. please help
Create an .xml file now implement a view flipper design the layout of how each pages work. I suggest using a relative layout and add those views inside the view flipper. Seems pretty basic now go search tuts on .xml, viewflippers, types of layout, textviews, and don't put questions here next time asking for answers. We are a community after all helping people with problems who actually tries to do something not for copy and paste people.
For this purpose it's best not to use the ViewFlipper, but instead use a ViewPager to which you can dynamically add 'subviews' (pages) using a PagerAdapter. ViewPager will provide performance benefits over ViewFlipper as it loads (and removes) pages on-demand (like a ListView).
Set-up of the ViewPager is in essence the same as setting up a ListView. You can use the ViewPager on Android <3.0 devices using the compatibility library.
Create your own class that extends PagerAdapter, and set mViewPager.setAdapter(mAdapter);. In your adapter, in the method instantiateItem() you will build your 'page' and add it to the parent with mViewPager.addView(newView);.
For a more detailed example of how to set-up a ViewPager see my answer here.

Categories

Resources