2013-11-28 132 views
0

期間滾動在以下項目here is example廣東話.notifyDataSetChanged()

我使用的是.notifyDataSetChanged();這種方法.post(new Runnable(){增加新的項目

private void addItemsToList() { 
      int randomVal = MIN + (int) (Math.random() * ((MAX - MIN) + 1)); 
      mItems.add(String.valueOf(randomVal)); 
      mListAdapter.notifyDataSetChanged(); 

      mCompleteListView.post(new Runnable(){ 
       public void run() { 
        mCompleteListView.setSelection(mCompleteListView.getCount() - 1); 
       }}); 
     } 


public class ReceiverThread extends Thread { 
    String line; 
    String name; 

    ReceiverThread(String name, String line){ 
     this.line=line; 
     this.name=name; 

    } 

    public void run() { 
    OpenStream.this.runOnUiThread(new Runnable() { 

       public void run() { 
        addItemsToList();}}}} 

時,我想通過滾動之後向下滾動使用手指,新的編程方式添加項目滾動列表視圖向下。

當我觸摸屏幕並使用手指進行滾動時,我該如何引發.post(new Runnable()?或者我能做些什麼來不讓ListView向下滾動,當我觸摸屏幕?

回答

1

我已經添加了這些代碼,而現在當我觸摸列表視圖沒有滾動向下

mCompleteListView.setOnTouchListener(new OnTouchListener() { 

    @Override 
    public boolean onTouch(View v, MotionEvent event) { 

    if (event.getAction() == MotionEvent.ACTION_UP) { 
    flag = true; 
    Log.e(MainActivity.tag,"onTouch "+flag); 
    }else{ 
    flag = false; 
    Log.e(MainActivity.tag,"onTouch "+flag); 
    } 

    return false; 
    } 
    });