0

我正在滚动列表视图。我想加载列表视图滚动的数据,我这样做:

    public void onScroll(AbsListView view, int firstVisibleItem,
            int visibleItemCount, int totalItemCount) {
        if (loading) {
            if (totalItemCount > previousTotal) {
                loading = false;
                previousTotal = totalItemCount;
            }
        } else {
            if ((totalItemCount - visibleItemCount) <= (firstVisibleItem + threshold)) {
                new loadMoreListView().execute();

                int currentPosition = lv.getFirstVisiblePosition();
                View v = lv.getChildAt(0);
                int distFromTop = (v == null) ? 0 : v.getTop();
                lv.setSelectionFromTop(currentPosition, distFromTop);
            }
        }
    } 

loadMoreListView 是使用 AsynTask 加载数据的类。我的问题是当我到达第 10 个位置时,listview 开始按预期加载数据,但它冻结了整个 listview。在加载数据之前,我无法与 listview 交互。是否有任何解决方案可以同时加载数据并与列表视图交互。请不要推荐 Endless Adapter 或 Prime。我已经用那个试过了。非常感谢任何帮助。提前致谢。

4

2 回答 2

0
public class LListviewsActivity extends Activity {
 ListView myList;
 Button getChoice;
 String[] listContent = {
        "January",
        "February",
         "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
         "October",
        "November",
        "December"
};

/** Called when the activity is first created. */
 @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    myList = (ListView)findViewById(R.id.list);
     getChoice = (Button)findViewById(R.id.getchoice);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
           android.R.layout.simple_list_item_multiple_choice,listContent);
    myList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    myList.setAdapter(adapter);
    getChoice.setOnClickListener(new Button.OnClickListener(){
        public void onClick(View v) {
           // TODO Auto-generated method stub
                       String selected = "";
              int cntChoice = myList.getCount();
              SparseBooleanArray sparseBooleanArray =              
     myList.getCheckedItemPositions();
           for(int i = 0; i < cntChoice; i++){
               if(sparseBooleanArray.get(i)) {
                   selected +=                      myList.getItemAtPosition(i).toString() + "\n";
               }
           } Toast.makeText(LListviewsActivity.this, selected          ,Toast.LENGTH_LONG).show();
         }
      });
  }
   }
于 2012-07-19T09:40:52.100 回答
0

试试这个,它工作

list_event.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState != 0)
                eventAdapter.isScrollingEvent = true;
            else {
                eventAdapter.isScrollingEvent = false;
                eventAdapter.notifyDataSetChanged();
            }
        }
    });

写 boolean isScrollingEvent=true
并且您的适配器类似于 eventAdapter

检查这个链接它是非常有用的 列表视图滚动不平滑

于 2014-03-19T08:45:14.300 回答