android listview - android

I'm using a list view in my app and which grows dynamically. Initially list contains same contents for entire list row. Each row in list view displays different contents as app progress. I used same list view foe displaying two type of contents. But the problem is when this happens the scrolling of list view become less smooth. please tell me why this happens.
Thanks in advance.

it is hard to tell what the problem is without looking at the code anyways are you using remote images in that listview? or custom listview you have created using base or arrayadapter? if yes then you will have definately perfomance related issue.

The most likely cause I've seen for this so far, is re-creating your View every time it's requested. You should rather see if the current View on your Handler is not created already. If it's created just update it, don't re-create it. If it's not then bring it from the scratch with new and all that stuff.
Basic Android List tutorials have some lines like (I can't remember exactly):
if(v == null){
v = new MyView(...);
}else{
((MyView)v).updateData();
}
return v;
Pay close attention to it.
Hope this helps.

Related

How to implement sectioned listview like in youtube app Android

Does someone know to implement this kind of views structure in Android ? It's from youtube app.
Thanks for your help.
Android have a great little tool when you want to know how something was done.
It's the DDMS (device monitor), look around on Eclipse or Android Studio that you can find it.
Over there, you will find the option: "Dump View hierarchy for UIAutomator" and you can use it to get the View hierarchy of different apps. So for example YouTube:
You can see that it's just a normal ListView with a very cleverly built Adapter. Check out carefully the BaseAdapter class https://developer.android.com/reference/android/widget/BaseAdapter.html
specially two methods:
int getViewTypeCount();
int getItemViewType(int position);
those can be used to have different types of view depending on the position of the ListView. So then it's just built one-by-one, the types you want to implement.
The "more" will do nothing more than add more items the data backing the adapter and call notifyDataSetChanged()
happy coding...
You would need to create more than 1 listview and use padding around it to create the space between one listview and another. You also need to make the layout where the listviews are setup scrollable.
I would personally setup a fragment for each listview to be able to load more data in each list.
Hope this helps. :)

Android: How to use fragments to completely change a view

My app has a custom segmented control(got it from internet - its really a radio group) and under it a listview. When a user clicks on a row in the list view, a fragment is attached to the activity that displays a different listview. This new listview seems to replace the old one. The problem is that the segmented control is still there, whereas I would like the whole view to be the new list view. Knowing that fragments are embedded in the view group, I thought progammatically removing the segmented control would work, but it didn't, the control just becomes empty space.
It's important that the app works the way I described. I could explain in detail why this is so, if needed.
Any tips? Much appreciated.

Is there a way to call BaseAdapter.notifyDataSetChanged() on a single object?

Is there a way to call BaseAdapter.notifyDataSetChanged() on a single element in the adapter.
What I am trying to do is update the data and reflect those changes in the containing ListView. The problem is that sometimes the change is so small that it seems ridiculous that I have to refresh the whole view rather than the single item in the view that has been updated.
I am not aware of such method. If it's really important, you can always find individual item view to update. But I don't think that it worth it as Android is pretty efficient in updating list views. So it will not do much extra work (definitelly not going beyond items currently visible on the screen).

Improving Scroll Smoothness in an Android ListView

I have a an Android ListView that has small (say, 1-5 frame) stutters as it is scrolling, about every second or so. I realize that many Android phones have these problems with animation smoothness, however, on my phone (Motorola A855 running Android 2.2), the native contact list scrolls quite smoothly. The item view in the contact list is more complex than the item view in my list, which is:
<RelativeLayout>
<TextView />
<TextView />
</RelativeLayout>
I only want to achieve smoothness as good as the native contact list. It seems like this should be possible without optimizing in native code, but perhaps I'm wrong about that.
I have tried a few things: I simplified the item view even further, and I tried instantiating it programmatically instead of in XML. I also tried changing the way I react to item click events, as per this link:
http://groups.google.com/group/android-developers/browse_thread/thread/7dc261a6b382ea74?pli=1
None of these things seem to have any effect on performance.
Is there anything I can do in my app to improve performance? I'm looking to deploy this app to a number of phones, so changing settings on the phone or rooting the device is not an option in my case. Here is the getView method from my adapter class:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater flater = (LayoutInflater)context.getSystemService(ListActivity.LAYOUT_INFLATER_SERVICE);
layout = flater.inflate(R.layout.song_view, parent, false);
TextView first = (TextView)layout.findViewById(R.id.firstLine);
TextView second = (TextView)layout.findViewById(R.id.secondLine);
Thing t = array.get(position);
first.setText(t.title);
second.setText(t.name);
return layout;
}
Thanks in advance!
It's difficult to know why this may be happening without seeing your code.
However, one place to look is your getView() method in your ListAdapter (assuming you're using a custom adapter). Try and re-use the View that's passed as an argument to this method rather than creating a new one each time. Also don't do anything too heavy in this method (e.g. a network call), in fact try to make it as lean and mean as possible for best performance.
Did you tried Efficient Adapter
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html
From my perspective, Problem of animation smoothness is due to garbage collector running in background. If you are creating lots of object then you will see lag in listview scroll.
Hope this help.

Android, how to stop reading getView() function again, if the content is already downloaded in the ListView

I am a newbie Android guy.
I have a ListView displaying images on every element of the ListView, It works fine... but when I start to scrolling I have realized my image is downloaded again if it is displayed in the screen of my phone device!
How could I stop reloading the images or all the content of the in ListView again?
Or how could I avoid reading the getView() function again If I have already downloaded all its content?
It is possible to create an efficient adapter with different view types. Take a look at this question.
It's fairly simple. Just need to override getItemViewType and getViewTypeCount. Then you can count on convertView being the correct view type.

Categories

Resources