搜索框自定义列表视图自定义、视图、列表

2023-09-04 23:23:16 作者:狗屎味的小仙女

我建一个coustom列表视图,至极充满了从SQLite的数据。 现在,我要为我的ListView这样的搜索框:https://lh5.googleusercontent.com/-0H2RUBsLIYQ/Th1lqLCn5iI/AAAAAAAAALg/QZe8a5-PYu0/custom_listview_search2.png>

这是我的活动:

 包de.bodprod.rettinfo;

进口的java.util.ArrayList;
进口的java.util.HashMap;
进口的java.util.List;

进口android.app.Activity;
进口android.os.AsyncTask;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.AdapterView;
进口android.widget.AdapterView.OnItemClickListener;
进口android.widget.ListAdapter;
进口android.widget.ListView;
进口android.widget.SimpleAdapter;

公共类AntidotList延伸活动{
    ArrayList的< HashMap的<字符串,字符串>> antidotList;

    的String [] sqliteIds;

    公共静态字符串TAG_ID =ID;
    公共静态字符串TAG_TOX =弓形虫;
    公共静态字符串TAG_ANTIDOT =antidot;

    ListView的LV;
    INT长度限制:Textlength = 0;
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);

        的setContentView(R.layout.antidotlist_layout);

        antidotList =新的ArrayList< HashMap的<字符串,字符串>>();
        LV =(ListView控件)findViewById(R.id.antidotlistlayout);

        lv.setOnItemClickListener(新OnItemClickListener(){
            公共无效onItemClick(适配器视图<>母公司视图中查看,INT位置,长的id){

            }
        });
        新loadStoreAntidots()执行();
    }

    类loadStoreAntidots扩展的AsyncTask<字符串,字符串,字符串> {
        @覆盖
        保护字符串doInBackground(字符串参数... args){
            //从后台线程更新UI
            runOnUiThread(新的Runnable(){
                公共无效的run(){
                    数据库处理器DB =新的数据库处理器(getApplicationContext());
                    名单< AntidotsClass> antidots = db.getAllAntidots();
                    sqliteIds =新的String [antidots.size()];

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

                        AntidotsClass S = antidots.get(ⅰ);

                        //创建新的HashMap
                        HashMap的<字符串,字符串>图=新的HashMap<字符串,字符串>();

                        //添加每个子节点HashMap中的key =>值
                        map.put(tag_id,分别s.getId()的toString());
                        map.put(TAG_TOX,s.getTox());
                        map.put(TAG_ANTIDOT,s.getAntidot());

                        //添加HashList到ArrayList中
                        antidotList.add(图)

                        //添加sqlite的ID阵列
                        //用于删除从SQLite的网站时,
                        sqliteIds [I] = s.getId()的toString()。
                    }
                    ListAdapter适配器=新SimpleAdapter(
                        AntidotList.this,
                        antidotList,R.layout.antidotlistitem_layout,
                        新的String [] {tag_id,分别TAG_TOX,TAG_ANTIDOT},
                        新的INT [] {R.id.sqlite_id,R.id.tox_layout,R.id.antidot_layout}
                    );
                    lv.setAdapter(适配器);
                }
            });
            返回null;
        }
    }
}
 

这是我的布局:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    风格=@风格/ MAINVIEW
    机器人:方向=垂直>
    < EditText上机器人:ID =@ + ID / EditText01
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_width =FILL_PARENT
        机器人:提示=俗尘>
    < /的EditText>
    <的ListView
        机器人:ID =@ + ID / antidotlistlayout
        风格=@风格/ MAINVIEW
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>
    < / ListView控件>
< / LinearLayout中>
 
自定义视图

我不知道如何建立在搜索的Funktion。

希望你能帮助我。

解决方案   

经过以下几个环节

链接1

链路2

I build a coustom listview, wich filled with data from SQLite. Now I want for my listview a search box like this: https://lh5.googleusercontent.com/-0H2RUBsLIYQ/Th1lqLCn5iI/AAAAAAAAALg/QZe8a5-PYu0/custom_listview_search2.png>

This is my activity:

package de.bodprod.rettinfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class AntidotList extends Activity{
    ArrayList<HashMap<String, String>> antidotList;

    String[] sqliteIds;

    public static String TAG_ID = "id";
    public static String TAG_TOX = "tox";
    public static String TAG_ANTIDOT = "antidot";

    ListView lv;
    int textlength=0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.antidotlist_layout);

        antidotList = new ArrayList<HashMap<String, String>>();
        lv = (ListView) findViewById(R.id.antidotlistlayout);

        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });        
        new loadStoreAntidots().execute();
    }

    class loadStoreAntidots extends AsyncTask<String, String, String> {
        @Override
        protected String doInBackground(String... args) {
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    DatabaseHandler db = new DatabaseHandler(getApplicationContext());
                    List<AntidotsClass> antidots = db.getAllAntidots();
                    sqliteIds = new String[antidots.size()];

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

                        AntidotsClass s = antidots.get(i);

                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_ID, s.getId().toString());
                        map.put(TAG_TOX, s.getTox());
                        map.put(TAG_ANTIDOT, s.getAntidot());

                        // adding HashList to ArrayList
                        antidotList.add(map);

                        // add sqlite id to array
                        // used when deleting a website from sqlite
                        sqliteIds[i] = s.getId().toString();
                    }
                    ListAdapter adapter = new SimpleAdapter(
                        AntidotList.this,
                        antidotList, R.layout.antidotlistitem_layout,
                        new String[] { TAG_ID, TAG_TOX, TAG_ANTIDOT },
                        new int[] { R.id.sqlite_id, R.id.tox_layout, R.id.antidot_layout }
                    );
                    lv.setAdapter(adapter);
                }
            });
            return null;
        }
    }
}

This is my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    style="@style/mainView" 
    android:orientation="vertical" >
    <EditText android:id="@+id/EditText01"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:hint="Suchen">                               
    </EditText>    
    <ListView
        android:id="@+id/antidotlistlayout"
        style="@style/mainView" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>           
</LinearLayout>  

I don't know how to build in the search funktion.

Hope you can help me

解决方案

go through the following links

Link1

Link2