过滤器的列表视图后,我如何获得的第一个列表视图的位置? [英] After filter a listview,how can I obtain the position of the first listview?
问题描述
过滤器的列表视图后,我怎么能获得第一个列表视图的位置? 我用simpleadapter来填充列表视图。 数据源中的每个项目都有自己的ID,我用案例来重定向他们。 当我过滤列表视图,我不知道如何联系起来的第一listview.The现在的位置和ID后面的项目发生了变化。 谢谢你。
我用EditTextView的afterTextChanged过滤列表视图,并通知了。 @覆盖
公共无效afterTextChanged(编辑paramEditable){
listItemsCopy.clear();
诠释计数= simpleAdapter.getCount();
如果((计数大于0)及&安培; paramEditable.length()大于0){
的for(int i = 0; I< simpleAdapter.getCount();我++){
地图<字符串,对象> tempMap =(地图<字符串,对象>)simpleAdapter.getItem(我);
。ItemName字符串= tempMap.get(姓名)的toString();
HashMap的<字符串,对象> tempHashMap =新的HashMap<字符串,对象>();
INT copyCount = 0;
如果(itemName.toLowerCase()。包含(paramEditable.toString()。与toLowerCase())){
tempHashMap =(&HashMap中所述;串,对象>)simpleAdapter.getItem(ⅰ);
listItemsCopy.add(tempHashMap);
copyCount ++;
}
}
如果(listItemsCopy!= NULL){
处理程序处理程序=新的处理程序();
handler.postDelayed(新的Runnable(){
@覆盖
公共无效的run(){
simpleAdaptercopy =新SimpleAdapter(getActivity()
listItemsCopy,R.layout.right_menu_list_view,新的String [] {
姓名,身份证,形象},新的INT [] {
R.id.rightMenuListViewTextView1,
R.id.rightMenuListViewTextView2,
R.id.rightMenuListViewImageView1});
simpleAdapter.setViewBinder(新ViewBinder(){
@覆盖
公共布尔setViewValue(查看视图,对象数据,
字符串textRe presentation){
如果((查看的instanceof的ImageView和放大器;&放大器;数据的instanceof位图)){
ImageView的IV =(ImageView的)观点;
iv.setImageBitmap((位图)的数据);
返回true;
} 其他 {
返回false;
}
}
});
listView.setAdapter(simpleAdaptercopy);
simpleAdapter.notifyDataSetChanged();
}
},1000);
}
}
其他 {
listView.setAdapter(simpleAdapter);
simpleAdapter.notifyDataSetChanged();
}
}
然后我想用列表视图的方法onItemClick重定向不同Intent.As数据源发生了变化,这两个位置,编号是不同,我想
@覆盖
公共无效onItemClick(适配器视图<>母公司视图中查看,
INT位置,长的id){
意向意图= NULL;
开关(位置){}`
我解决售后服务这三个阵列。只有测试code:
字符串positionString [] =新的String [22];
INT latterPosition [] =新的INT [22];
的for(int i = 0; I< latterPosition.length;我++){
positionString [I] =;
latterPosition [I] = 0;
}
INT latterCount = 0;
的for(int i = 0; I< positions.length;我++){
如果(位置[I] == 10){
positionString [latterCount] = 1 +;
latterPosition [latterCount] = 10;
latterCount ++;
}
}
After filter a listview,how can I obtain the position of the first listview? I use simpleadapter to fill the listview. Each item in the datasource has its own id,and I use "case" to redirect them. After I filter the listview ,I don't know how to associate the latter items with the first listview.The postion and id have changed. Thank you.
I use the afterTextChanged of EditTextView to filter the listview and notify it. @Override
public void afterTextChanged(Editable paramEditable) {
listItemsCopy.clear();
int count=simpleAdapter.getCount();
if ((count>0 )&¶mEditable.length()>0) {
for (int i = 0; i < simpleAdapter.getCount(); i++) {
Map<String,Object> tempMap=(Map<String,Object>)simpleAdapter.getItem(i);
String itemName=tempMap.get("name").toString();
HashMap<String, Object> tempHashMap=new HashMap<String, Object>();
int copyCount=0;
if(itemName.toLowerCase().contains(paramEditable.toString().toLowerCase())){
tempHashMap=(HashMap<String, Object>)simpleAdapter.getItem(i);
listItemsCopy.add(tempHashMap);
copyCount++;
}
}
if(listItemsCopy!=null){
Handler handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
simpleAdaptercopy = new SimpleAdapter(getActivity(),
listItemsCopy, R.layout.right_menu_list_view, new String[] {
"name", "id", "image" }, new int[] {
R.id.rightMenuListViewTextView1,
R.id.rightMenuListViewTextView2,
R.id.rightMenuListViewImageView1 });
simpleAdapter.setViewBinder(new ViewBinder() {
@Override
public boolean setViewValue(View view, Object data,
String textRepresentation) {
if ((view instanceof ImageView && data instanceof Bitmap)) {
ImageView iv = (ImageView) view;
iv.setImageBitmap((Bitmap) data);
return true;
} else {
return false;
}
}
});
listView.setAdapter(simpleAdaptercopy);
simpleAdapter.notifyDataSetChanged();
}
}, 1000);
}
}
else {
listView.setAdapter(simpleAdapter);
simpleAdapter.notifyDataSetChanged();
}
}
Then I want to use the method onItemClick of listview to redirect different Intent.As the datasource has changed,both position and id are different from which I want
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = null;
switch (position) {}`
I slove it with three arrays. Only test code:
String positionString[]=new String[22];
int latterPosition[]=new int[22];
for (int i = 0; i < latterPosition.length; i++) {
positionString[i]="";
latterPosition[i]=0;
}
int latterCount=0;
for (int i = 0; i < positions.length; i++) {
if (positions[i]==10) {
positionString[latterCount]=i+"";
latterPosition[latterCount]=10;
latterCount++;
}
}
这篇关于过滤器的列表视图后,我如何获得的第一个列表视图的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!