android 點擊listview 展開和閉合 效果

來源:互聯網
上載者:User

android 點擊listview 展開和閉合 效果

現在公司做的是電商項目,在我的優惠券介面中有個未使用和已使用, 在列表中要求 點擊item 把下面的刪除按鈕顯示出來,點擊其他item的時候把 之前顯示的 隱藏把正被點擊的item下的刪除按鈕顯示出來,這個其實很簡單,但是有一個問題就是如果點擊了一個item此時他是顯示的 但是再點擊同一個item的話 按到底要把它隱藏,這是考慮一個邏輯能力了,思考了一小時發現很簡單 現在貼一下關鍵的代碼

1:首先定義一個數組 int[] no_user_coupon = new int[1];//未使用

2:初始化數組值:no_user_coupon[0] = -1;

3;在listview點擊事件中做一下邏輯判斷

N_MyListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterViewparter, View v, int postion,long arg3) {
if(no_user_coupon[0]==postion){
no_user_coupon[0] = -1;
mPosition =postion;
mN_Adapter.setPosition(mPosition,true);
mN_Adapter.notifyDataSetChanged();
}else{
no_user_coupon[0] = postion;
mPosition =postion;
mN_Adapter.setPosition(mPosition,false);
mN_Adapter.notifyDataSetChanged();
}

4:在adapter中的getView方法中 代碼

if(mPosition==position){
if(isSamePosition){
rl_check_coupon_and_delete.setVisibility(View.GONE);
}else{
rl_check_coupon_and_delete.setVisibility(View.VISIBLE);
}
}else{
rl_check_coupon_and_delete.setVisibility(View.GONE);
}

 

OK 在此記錄下

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.