gpt4 book ai didi

android - listview getItemAtPosition() 方法的输出给出不可读的输出

转载 作者:行者123 更新时间:2023-11-29 21:10:40 26 4
gpt4 key购买 nike

我的 listview 来自其 id 为 @android:id/list 的布局。它是 android.R.id.list 的一部分。我使用 SimpleCursorAdaptersetAdapterlistview。 ListView 包含带有联系人姓名的复选框,例如 Emily Andrews、Susan John...我想知道用户选择的联系人姓名。当我使用下面的代码时,它会打印一个对象 android.content.ContentResolver.cursorWrapper... 我不确定如何解释它并知道选择了哪个联系人姓名。有没有办法让 listview.getItemAtPosition() 的输出可读?

代码:

 public void blockCheckedItems(View view) {  
// int cntChoice = lv.getCount();
checked = new ArrayList<String>();
unchecked = new ArrayList<String>();

int itempositions=adapter.getCount();

SparseBooleanArray sparseBooleanArray = lv.getCheckedItemPositions();
int countChoice = lv.getChildCount();

Log.d("" + countChoice, "CountChoice===============================");
Log.d("" + sparseBooleanArray,"sparseBooleanArray -------------------------");



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

if(sparseBooleanArray.get(i) == true)
{
checked.add(lv.getItemAtPosition(i).
.toString());

}
else if(sparseBooleanArray.get(i) == false)
{
unchecked.add(lv.getItemAtPosition(i).toString());
}

}
for(int i = 0; i < checked.size(); i++){
Log.d("checked list&&&&&&&&&&&&&&&&&&&", "" + checked.get(i));
}
for(int i = 0; i < unchecked.size(); i++){
Log.d("in unchecked list&&&&&&&&&&&&&&&&&&&", "" + unchecked.get(i));
}


}

最佳答案

当 ListView 适配器是光标适配器时,listview.getItemAtPosition() 返回指向该行的光标。所以你必须像这样从游标中获取数据:

Cursor cursor = listview.getItemAtPosition();
String name = cursor.getString(0);

我只是假设 0 是 first name 列在游标所代表的数据库中的索引,它可能是 2 、 3 ...

关于android - listview getItemAtPosition() 方法的输出给出不可读的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22980467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com