关于android.widget.ListView.getCheckedItemPositions() .size()

最近学习android,在书上看到一个实例,当listView上没有东西被选中的时候,getCheckedItemPositions() .size()得到的值确不是0,以下是代码 Platform 2.2

 

 

private void showMulti(){
		AlertDialog ad = new AlertDialog.Builder(this).setTitle("选择省份").
			setMultiChoiceItems(provinces, defualShow, new DialogInterface.OnMultiChoiceClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which, boolean isChecked) {
					
				}
			}).setPositiveButton("确定", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					
					String s = "你选择了:";
					for(int i =0; i<provinces.length;i++){
						if(lv.getCheckedItemPositions().get(i)){
							s += i+":"+lv.getAdapter().getItem(i)+",";
							Log.d("info", i+" is checked");
						}
					}
					
					if(lv.getCheckedItemPositions().size()>0){
						Log.d("info", lv.getCheckedItemPositions().size());
						new AlertDialog.Builder(Main.this).setMessage(s).show();
					}else{
						new AlertDialog.Builder(Main.this).setMessage("什么也没选").show();
					}
				}
			}).setNegativeButton("取消", null)
			.create();
		lv = ad.getListView();
		ad.show();
	}
 

 

 



 点击Show Mutil后,如果先选择几个,再将其全部取消

 

      
 
 得到的结果确是



 而不是预期结果



 由此推测出lv.getCheckedItemPositions().size()>0,但在lv.getCheckedItemPositions().get(i)进行判断的时候确实没得到被

选中的item, 这里纳闷了,看其doc说明 

 

public SparseBooleanArray getCheckedItemPositions ()
Since: API Level 1

Returns the set of checked items in the list.

 

应该是得到选中的列表,事实上得到的size确不是0,而是2,虽然可以通过其它方法来解决这个bug,但这里道底是程序的逻辑问题,还是我对API的理解错误,有点纠结

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
# -*- coding: UTF-8 -*- from lib2to3.pgen2 import driver from appium import webdriver from appium.webdriver.common.appiumby import AppiumBy el1 = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="通讯录") el1.click() el2 = driver.find_element(by=AppiumBy.XPATH, value="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.ListView/android.widget.FrameLayout[3]/android.widget.RelativeLayout") el2.click() el3 = driver.find_element(by=AppiumBy.XPATH, value="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[1]/android.widget.TextView") el3.click() el4 = driver.find_element(by=AppiumBy.XPATH, value="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[8]") el4.click() el5 = driver.find_element(by=AppiumBy.XPATH, value="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[11]") el5.click()
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值