Android中怎么利用item實(shí)現(xiàn)長(zhǎng)按刪除功能,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

一般寫(xiě)完之后都會(huì)調(diào)用
public void removeItem(int pos){
this.mDatas.remove(pos);
notifyItemRemoved(pos);
}可是這樣寫(xiě)的話(huà),刪除多次,會(huì)亂套,沒(méi)有刷新
所以改這樣子寫(xiě)
public void removeItem(int pos){
this.mDatas.remove(pos);
notifyItemRemoved(pos);
if(pos != mDatas.size()){ // 如果移除的是最后一個(gè),忽略
notifyItemRangeChanged(pos, mDatas.size() - pos);
}
}PS:下面看下android 長(zhǎng)按刪除listview的item
首先要繼承OnItemLongClickListener
public class Set_Music extends ListActivity implements OnItemLongClickListener{然后設(shè)置權(quán)限:
getListView().setOnItemLongClickListener(this);
重寫(xiě)方法
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String str = list.get(arg2).get("name");刪掉長(zhǎng)按的item
list.remove(arg2);
動(dòng)態(tài)更新listview
adapter.notifyDataSetChanged();
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。
文章名稱(chēng):Android中怎么利用item實(shí)現(xiàn)長(zhǎng)按刪除功能-創(chuàng)新互聯(lián)
文章鏈接:http://www.yijiale78.com/article4/doccie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、微信公眾號(hào)、App開(kāi)發(fā)、小程序開(kāi)發(fā)、外貿(mào)建站、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容