开发者

Android : Is it better to choose ViewwGroup then ListView for below case in android?

开发者 https://www.devze.com 2023-01-28 11:55 出处:网络
I my application i need a list of items , where each item contains TextView ProgressBar Download button

I my application i need a list of items , where each item contains

  1. TextView
  2. ProgressBar
  3. Download button
  4. Cancel button

when ever i click on download button progressBar starts and running its fine. . I have binded each row view to my data Object . In download task i.e; asynctask am using this view to update. But when am scrolling the list , progress is visible at differnt row then actual row.I dont know the reason ?

So, i decided to avoid listview and go by creating Viewgroup , then adding all views linearly these views. (But i donno how to handle OnclickListens for download , button and cancel Button ) Is it good way or any other possible way to do ? performance role ? Can any one help me开发者_JS百科 out these please ?

Thanking you ,

Srinivas


How long is your list?

If < 10 items (round about, you need to check). I would switch from ListView to

  • ScrollView
    • LinearLayout
      • Item 1
      • Item 2
      • Item 3

where each of your items contain the items etc. And it's still scrollable.

Then, I would attach a TAG to each ITEM and use the tag in a onClick handler:

public void handleClick(View v) {
    // use v.getTag();
}

Tag you can define in XML via android:tag="1234" or in code.

If you know what your ViewParent is (which class), then you can also CAST it to the appropriate class and get the "tag" from there.


Android is heavily reusing views that comprise each slot of your ListView. As you scroll these views are getting reuse again and again so you need take care of reassigning right progress status to your items as these become hidden/visible

Said that I would actually advise against creating more than one or two AsyncTask since you will surely choke the system with too many threads.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号