如何创建含底座适配器搜索 [英] How to create search with base adapter
本文介绍了如何创建含底座适配器搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建带有底座适配器搜索选项?以下是我已经尝试了样品code ......请提示
公共类ListViewAdapter延伸BaseAdapter
{//创建一个适配器,我们不得不延长BaseAdapter而不是活动,或什么的。 私人活动活动;
私人的ArrayList<&HashMap的LT;字符串,字符串>>数据;
私有静态LayoutInflater吹气= NULL;
公共ListViewAdapter(活动一,ArrayList的<&HashMap的LT;字符串,字符串> D 1和D){
活性=一个;
数据= D;
吹气=(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);}公众诠释的getCount(){//获取ListView中元素的个数
返回data.size();
}公共对象的getItem(INT位置){//此方法的对象按位置返回
返回的位置;
}众长getItemId(INT位置){//通过位置获取项目ID
返回的位置;
}公共查看getView(INT位置,查看convertView,父母的ViewGroup){// getView方法是与我们的个性化行填充列表视图的方法
查看VI = convertView;
如果(convertView == NULL)
VI = inflater.inflate(R.layout.layout1,NULL); //列表视图中的每一个项目使用XMLlistview_row的设计 TextView的ID =(TextView中)vi.findViewById(R.id.textView1); //这里是在listview_row XML文件中的两个textviews
TextView的名字=(TextView中)vi.findViewById(R.id.textView2); //你可以输入你想要的任何东西,按钮,单选按钮,图像等
TextView的LOC =(TextView中)vi.findViewById(R.id.textView3);
TextView的DESC =(TextView中)vi.findViewById(R.id.textView4);
TextView的状态=(TextView中)vi.findViewById(R.id.textView5); HashMap的<字符串,字符串>哈希=新的HashMap<字符串,字符串>(); //我们需要一个HashMap来存储我们的数据对任何项目
哈希= data.get(位置);
id.setText(hash.get(SaActivity.KEY_ACCOUNTNUMBER)); //我们个性化我们行的项目。
name.setText(hash.get(SaActivity.KEY_NAME));
loc.setText(hash.get(SaActivity.KEY_STATUS));
desc.setText(hash.get(SaActivity.KEY_DESC));
status.setText(hash.get(SaActivity.KEY_NAME)); 返回VI;
} }
解决方案
你必须学习基本的东西有关适配器和搜索控制,然后尝试实现你想要什么。首先
我建议你看看这个一>,并尝试实现你想要的。这是仅供参考,了解你的概念。
享受学习
How to create search option with base adapter? Here is the sample code which i have tried......pls suggest
public class ListViewAdapter extends BaseAdapter
{ //To create an adapter we have to extend BaseAdapter instead of Activity, or whatever.
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ListViewAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() { //get the number of elements in the listview
return data.size();
}
public Object getItem(int position) { //this method returns on Object by position
return position;
}
public long getItemId(int position) { //get item id by position
return position;
}
public View getView(int position, View convertView, ViewGroup parent) { //getView method is the method which populates the listview with our personalized rows
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.layout1, null); //every item in listview uses xml "listview_row"'s design
TextView id = (TextView)vi.findViewById(R.id.textView1); //Here are two textviews in the listview_row xml file
TextView name = (TextView)vi.findViewById(R.id.textView2); // You can enter anything you want, buttons, radiobuttons, images, etc.
TextView loc = (TextView)vi.findViewById(R.id.textView3);
TextView desc = (TextView)vi.findViewById(R.id.textView4);
TextView status = (TextView)vi.findViewById(R.id.textView5);
HashMap<String, String> hash = new HashMap<String, String>(); //We need a HashMap to store our data for any item
hash = data.get(position);
id.setText(hash.get(SaActivity.KEY_ACCOUNTNUMBER)); //We personalize our row's items.
name.setText(hash.get(SaActivity.KEY_NAME));
loc.setText(hash.get(SaActivity.KEY_STATUS));
desc.setText(hash.get(SaActivity.KEY_DESC));
status.setText(hash.get(SaActivity.KEY_NAME));
return vi;
}
}
解决方案
First of all you have to learn basic thing about adapter and search control and then try to implement what you want.
I suggest you to see this and try to implement as you want. This is only for reference to learn your concept.
Enjoy Learning
这篇关于如何创建含底座适配器搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文