得到的ListView选中项的安卓 [英] get checked items from listview in android

查看:117
本文介绍了得到的ListView选中项的安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态的列表视图与一个文本每line.when一个复选框我点击一个按钮,我需要得到所有选中的项目名称和放大器。未经检查的项目名称分别为arraylilst.How可能我做that.Examples要好得多。

我用..

  SparseBooleanArray检查= mainlw.getCheckedItemPositions();

    的for(int i = 0; I< checked.size();我++){

        如果(checked.valueAt(一)==真){
            行星标签=(星球)mainlw.getItemAtPosition(checked.keyAt(一));

            串selectedName = tag.getName();
            Toast.makeText(getApplicationContext(),selectedName,Toast.LENGTH_SHORT).show();
        }
    }
 

解决方案

尝试了这一点,并根据您的要求实现这个逻辑。

  INT cntChoice = myList.getCount();

字符串检查=;

字符串未选中=;
SparseBooleanArray sparseBooleanArray = myList.getCheckedItemPositions();

的for(int i = 0; I< cntChoice;我++)
{

     如果(sparseBooleanArray.get(一)==真)
     {
         检查+ = myList.getItemAtPosition(I)的ToString()+\ N的;
     }
     否则,如果(sparseBooleanArray.get(一)==假)
     {
         未选中+ = myList.getItemAtPosition(I)的ToString()+\ N的;
     }

 }
 

I have a dynamic listview with one text and one checkbox per line.when i click a button.,i need to get all checked item names & Unchecked item names separately as arraylilst.How could i do that.Examples are much better..

I used..

    SparseBooleanArray checked = mainlw.getCheckedItemPositions();

    for (int i = 0; i < checked.size(); i++) {

        if(checked.valueAt(i) == true) {
            Planet tag = (Planet) mainlw.getItemAtPosition(checked.keyAt(i));

            String selectedName=tag.getName();
            Toast.makeText(getApplicationContext(), selectedName, Toast.LENGTH_SHORT).show();
        }
    }

解决方案

Try this out and implement this logic according to your requirement.

int cntChoice = myList.getCount();

String checked = "";

String unchecked = "";
SparseBooleanArray sparseBooleanArray = myList.getCheckedItemPositions();

for(int i = 0; i < cntChoice; i++)
{

     if(sparseBooleanArray.get(i) == true) 
     {
         checked += myList.getItemAtPosition(i).toString() + "\n";
     }
     else  if(sparseBooleanArray.get(i) == false) 
     {
         unchecked+= myList.getItemAtPosition(i).toString() + "\n";
     }

 }

这篇关于得到的ListView选中项的安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆