2011-09-13 47 views
1

點擊列表項時,我有一點功能可以敲出列表視圖並且不會觸發列表視圖。我的代碼在這裏:列表視圖ListItem中的Strike out和unstrikeout

public void markComplete(View v) 
{ 
    Button b1 = (Button)findViewById(R.id.Completeit); 
    Button b2 = (Button)findViewById(R.id.InCompleted); 


    try{ 
     TextView tv = (TextView)findViewById(R.id.textViewx); 
    tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); 
    }catch(Exception e){e.printStackTrace();} 

    b1.setVisibility(-1); 
    b2.setVisibility(1); 

} 

public void markInComplete(View v) 
{ 
    Button b1 = (Button)findViewById(R.id.Completeit); 
    Button b2 = (Button)findViewById(R.id.InCompleted); 


    try{ 
     TextView tv = (TextView)findViewById(R.id.textViewx); 
     tv.setPaintFlags(tv.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG)); 
    }catch(Exception e){e.printStackTrace();} 
    b1.setVisibility(1); 
    b2.setVisibility(-1); 
} 

我有兩個按鈕用於檢查和取消選中列表項。它僅適用於第一個列表項。如果我嘗試點擊第二個列表項目,則僅在第一個項目上完成醒目的&無劃痕。任何幫助表示感謝,並提前致謝

+0

是每個listview行中的這些按鈕嗎? – blessenm

回答

1

您的findViewById調用將返回它找到的視圖中的第一個元素。如果你有多個,那麼這將是一個問題。它總是會找到第一個表格單元格。這裏的解決方案是保存按鈕,並將每個單元視爲單獨的視圖。

+0

如何做到這一點? –

+0

將每個單元格的佈局充滿不同的視圖,然後您可以爲該子視圖使用findById。祝你好運! –