ListView中CheckBox使用問題,listviewcheckbox

來源:互聯網
上載者:User

ListView中CheckBox使用問題,listviewcheckbox

      由於CheckBox的點擊事件優先順序比ListView的高,所以當ListView中使用CheckBox會導致ListView的setOnItemClickListener失去響應。

解決辦法:在CheckBox中添加android:focusable="false",使得CheckBox初始的時候沒有擷取焦點。 

      如果想在單擊CheckBox時響應的是ListView的ItemClick事件可以設定CheckBox的android:clickable="false"屬性。

應用樣本:


list.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view,int position, long id) {// TODO Auto-generated method stubCheckBox checkBox=(CheckBox) view.findViewById(R.id.cbSelect);checkBox.toggle();if ( checkBox.isChecked()) {// 添加該清單項目的電話號碼sendList.add(numList.get(position));sendName.add(nameList.get(position));}else {//從群發列表中移除電話號及姓名sendList.remove(numList.get(position));sendName.remove(nameList.get(position));}Toast.makeText(SelectContacts.this,"position:"+position+"\nnumList.size():"+numList.size(),Toast.LENGTH_SHORT).show();}});




在listview中的checkbox怎使用

procedure TForm1.FormCreate(Sender: TObject);
var
i:Integer;
begin
for I:=0 to lv1.items.count-1 do
if lv1.Items[I].Checked then //某一行被選中了
begin
//add code here
end;
end;



 
對於Android中listView列表checkBox亂序的問題,解答!!!

這是item布局重用導致的。你可以在ViewHolder中聲明一個int類型的ID,並寫一個有參構造。每次new的時候傳入 position;
再寫一個全域的List集合,只要選中CheckBox就將這個Id加到這個list中,反之則從list中remove掉。這樣在getView()方法中只要是position存在list中則把CheckBox的屬性設為true反之為false.這樣就不會混亂了。這個和圖文混排時的錯亂是一樣的。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.