在simple_list_item_multiple_choice搜索返回错误值错误 [英] Search in simple_list_item_multiple_choice return wrong value Wrong
问题描述
我做了一个simple_list_item_multiple_choice ListView和在列表视图化妆过滤器的EditText。
我需要过搜索我的价值观,并将其标记+另一个值;
但是任何搜索后,列表视图中显示虚假的价值,它的返回值,而不是位置值;
像这样的图片:
1 - 起初我有联系人数据列表:
2 - 搜索联系人和choesn:
3 - 但搜索和清除搜索字段(EditText上)与选择的位置,列表视图显示项目之后,没有选择的值:
我需要这样的:
有关要将过滤器我用这个:
ArrayAdapter<串GT; cnct_List_Adapter = =新ArrayAdapter<串GT;(getActivity(),android.R.layout.simple_list_item_multiple_choice,资讯); contacsList =(ListView控件)dialog.findViewById(R.id.LvGroupContacts);
contacsList.setTextFilterEnabled(真); contacsList.setAdapter(cnct_List_Adapter); @覆盖
公共无效onTextChanged(CharSequence的CS,INT ARG1,ARG2 INT,INT ARG3)
{
。cnct_List_Adapter.getFilter()过滤器(CS); }
修改 的ListView适配器
ArrayAdapter<串GT; cnct_List_Adapter =新ArrayAdapter<串GT;(getActivity(),R.layout.contacts_list_custom,资讯); 最终的ListView LvPopupContacts =(ListView控件)dialog.findViewById(R.id.LvPopupContacts);
LvPopupContacts.setAdapter(cnct_List_Adapter);
在这里我填写阵列:
dialog.findViewById(R.id.FrameLayout_botton).setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v)
{
selected_contacts = NULL;
尝试
{
SparseBooleanArray检查= LvPopupContacts.getCheckedItemPositions();
的for(int i = 0; I< checked.size();我++)
{
如果(checked.valueAt(我)==真)
{
selected_contacts = LvPopupContacts.getItemAtPosition(checked.keyAt(i)).toString().replaceAll(\"\\\\D+\",\"\")+\",\"+selected_contacts;
}
((TextView的)view.findViewById(R.id.TvContactsCount))的setText(将String.valueOf(checked.size()));
}
dialog.dismiss();
}赶上(例外五){
Toast.makeText(getActivity(),e.toString(),0).show();
}
}
});
我觉得在你的筛选列表,你已经签'Contact1',所以过滤列表中只包含你的'Contact1和 LvPopupContacts。 getCheckedItemPositions()
将在第一个索引返回一个true的阵列和检查(SparseBooleanArray)包含数组的第一位置的真实。为此,如果您使用的是阵列重新检查未筛选列表,其结果必然是从第一行选中为你以前提到的列表。你必须更新检查阵列(大小和内容)当你的列表视图过滤得到这很容易定义适配器。
我强烈建议你使用自定义适配器有超过适配器做这样的事情完全控制;没有自定义适配器类的调试是头疼。
i made a listview with simple_list_item_multiple_choice and a edittext for make filter in listview.
i need too search my values and mark them + another values;
but after any search , list view show false value , it return value position instead value; like this images:
1 - at first i have list with contact data:
2 - search contacts and choesn :
3 - but after search and clear search field (With EditText) , listview show item with chosen position , no chosen value :
i need this :
for make filter i used this :
ArrayAdapter<String> cnct_List_Adapter= =new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_multiple_choice,info);
contacsList =(ListView)dialog.findViewById(R.id.LvGroupContacts);
contacsList.setTextFilterEnabled(true);
contacsList.setAdapter(cnct_List_Adapter);
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3)
{
cnct_List_Adapter.getFilter().filter(cs);
}
Edit ListView Adapter
ArrayAdapter<String> cnct_List_Adapter =new ArrayAdapter<String>(getActivity(),R.layout.contacts_list_custom,info);
final ListView LvPopupContacts=(ListView)dialog.findViewById(R.id.LvPopupContacts);
LvPopupContacts.setAdapter(cnct_List_Adapter);
and here i fill Array :
dialog.findViewById(R.id.FrameLayout_botton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
selected_contacts=null;
try
{
SparseBooleanArray checked = LvPopupContacts.getCheckedItemPositions();
for (int i = 0; i < checked.size(); i++)
{
if(checked.valueAt(i) == true)
{
selected_contacts = LvPopupContacts.getItemAtPosition(checked.keyAt(i)).toString().replaceAll("\\D+","")+","+selected_contacts;
}
((TextView)view.findViewById(R.id.TvContactsCount)).setText(String.valueOf(checked.size()));
}
dialog.dismiss();
} catch (Exception e) {
Toast.makeText(getActivity(), e.toString(), 0).show();
}
}
});
i think in your filtered list you've checked 'Contact1' , so the filtered list contains just your 'Contact1' and LvPopupContacts.getCheckedItemPositions()
will return an array with a true at first index and the checked(SparseBooleanArray) contains a True at first position of the array. therefor if you are using that array to re check unfiltered list , the result would be a list with the first row checked as you 've mentioned . you have to update the checked array(size and contents) when your listview get filtered which would be implemented inside Custom adapter easily.
i highly recommend you to use custom adapters to have complete control over your adapter for doing such things ; without custom adapter class debugging would be headache.
这篇关于在simple_list_item_multiple_choice搜索返回错误值错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!