2011-12-12 68 views
0

如何在ListView中的位置X處獲取視圖?我不想膨脹一個新的,只是檢索在屏幕上可見的單元格以編程方式更改一些參數在ListView的位置X處獲取視圖

+0

您正在使用哪個適配器? – havexz

+0

ArrayListAdapter – Addev

回答

1

發現了一個骯髒的解決方案:

  1. 你應該能夠識別產生的每一行。例如添加與能見度一個TextView =消失,併產生當寫一個唯一值存在(或回收的行)
  2. 在listactivity調用getListView.setSelection(位置)到所需的細胞
  3. 調查列表視圖列表行(直至顯示)

    lv=getListView(); 
    for (int i=0;i <lv.getChildCount();i++){ 
        if (((TextView)lv.findViewById(R.id.my_hidden_textview)).getText.equals(mykey)){ 
        // view found 
        } else { 
        // schedule another survey "soon" 
        } 
    } 
    

    日程表,你可以使用類似:

    final int RETRY_DELAY=100; 
    new Handler(){ 
        public void handleMessage(Message msg){ 
         if (msg.what<0) return; //something went wrong and retries expired 
           lv=getListView(); 
         for (int i=0;i <lv.getChildCount();i++){ 
         if (((TextView)lv.findViewById(R.id.my_hidden_textview)).getText.equals(mykey)){ 
          //result = lv.findViewById(R.id.my_hidden_textview); 
         } else { 
          this.sendEmptyMessageDelayed(msg.what-1,RETRY_DELAY); 
         } 
         }  
        } 
    }.sendEmptyMessageDelayed(10,RETRY_DELAY); 
    

正如我所說是一個非常醜陋的解決方案,但它的工作

2

由於ListView中的視圖重新使用/重新循環。沒有從ListView獲取視圖引用的直接方式。

如果要訪問視圖,您需要擴展ArrayAdapter,然後覆蓋getView。在那裏您應該撥打super.getView並編寫您自己的自定義代碼。

如果我們確實需要控制更多的嘗試延伸BaseAdapterCursorAdapter

1

我沒有清楚地理解你的問題。但根據我的理解,我建議您在線性佈局內使用框架佈局。您可以使用其他框架佈局來進行操作。