Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何实现对使用ListAdapater、ArrayList和HashMap的ListView的搜索_Android_Search_Arraylist_Android Listview_Listadapter - Fatal编程技术网

Android 如何实现对使用ListAdapater、ArrayList和HashMap的ListView的搜索

Android 如何实现对使用ListAdapater、ArrayList和HashMap的ListView的搜索,android,search,arraylist,android-listview,listadapter,Android,Search,Arraylist,Android Listview,Listadapter,我有一个从JSON数组填充的列表视图。首先从JSON数组中提取值,然后将其放入HashMap中。然后将此HashMap添加到ArrayList中。从这里,必要的数据被添加到ListAdapter 我在网上搜索了好几天,想找到一种方法给它添加一个搜索功能,但没有一个使用ListAdapater、ArrayList和HashMap的组合。我是初学者,有人能帮我吗 这是我的密码 public class ListNew extends Activity { ListView list; TextVie

我有一个从JSON数组填充的列表视图。首先从JSON数组中提取值,然后将其放入HashMap中。然后将此HashMap添加到ArrayList中。从这里,必要的数据被添加到ListAdapter

我在网上搜索了好几天,想找到一种方法给它添加一个搜索功能,但没有一个使用ListAdapater、ArrayList和HashMap的组合。我是初学者,有人能帮我吗

这是我的密码

public class ListNew extends Activity {
ListView list;
TextView eid;
TextView ename; 
TextView edesc;
//Button Btngetdata;
ArrayList<HashMap<String, String>> oslist = new ArrayList<HashMap<String, String>>();

//URL to get JSON Array
private static String url = "somelink";

//JSON Node Names 
private static final String TAG_OS = "events";
private static final String TAG_EID = "eid";
private static final String TAG_ENAME = "ename";
private static final String TAG_ETYPE = "etype";
private static final String TAG_EDESC = "edesc";
private static final String TAG_ESDATE = "esdate";
private static final String TAG_EEDATE = "eedate";
private static final String TAG_ESTIME = "estime";
private static final String TAG_EETIME = "eetime";
private static final String TAG_LOCATION = "location";
private static final String TAG_CREATED_AT = "created_at";
private static final String TAG_EDITED_AT = "edited_at";
private static final String TAG_CREATEDBY = "createdby";
private static final String TAG_IMAGE = "image";
private static final String TAG_APPROVED = "approved";

EditText inputSearch;
ListAdapter adapter;


public static final String TABLE_EVENT = "event";



JSONArray events = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //from here
    inputSearch = (EditText) findViewById(R.id.etSearch);

    setContentView(R.layout.listnew);
    oslist = new ArrayList<HashMap<String, String>>();

    new JSONParse().execute();


}

private class JSONParse extends AsyncTask<String, String, JSONObject> {
     private ProgressDialog pDialog;
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
         eid = (TextView)findViewById(R.id.vers);
         ename = (TextView)findViewById(R.id.name);
         edesc = (TextView)findViewById(R.id.api);
        pDialog = new ProgressDialog(ListNew.this);
        pDialog.setMessage("Getting Data ...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();



    }

    @Override
    protected JSONObject doInBackground(String... args) {

        JSONParser jParser = new JSONParser();

        // Getting JSON from URL
        JSONObject json = jParser.getJSONFromUrl2(url);
        return json;
    }
     @Override
     protected void onPostExecute(JSONObject json) {
         pDialog.dismiss();
         try {
                // Getting JSON Array from URL
                events = json.getJSONArray(TAG_OS);
                for(int i = 0; i < events.length(); i++){
                JSONObject c = events.getJSONObject(i);

                // Storing  JSON item in a Variable
                String eid = c.getString(TAG_EID);
                String ename = c.getString(TAG_ENAME);
                String etype = c.getString(TAG_ETYPE);
                String edesc = c.getString(TAG_EDESC);
                String esdate = c.getString(TAG_ESDATE);
                String eedate = c.getString(TAG_EEDATE);
                String estime = c.getString(TAG_ESTIME);
                String eetime = c.getString(TAG_EETIME);
                String location = c.getString(TAG_LOCATION);
                String created_at = c.getString(TAG_CREATED_AT);
                String edited_at = c.getString(TAG_EDITED_AT);
                String createdby = c.getString(TAG_CREATEDBY);
                String image = c.getString(TAG_IMAGE);
                String approved = c.getString(TAG_APPROVED);

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

                map.put(TAG_EID, eid);
                map.put(TAG_ENAME, ename);
                map.put(TAG_ETYPE, etype);
                map.put(TAG_EDESC, edesc);
                map.put(TAG_ESDATE, esdate);
                map.put(TAG_EEDATE, eedate);
                map.put(TAG_ESTIME, estime);
                map.put(TAG_EETIME, eetime);
                map.put(TAG_LOCATION, location);
                map.put(TAG_CREATED_AT, created_at);
                map.put(TAG_EDITED_AT, edited_at);
                map.put(TAG_CREATEDBY, createdby);
                map.put(TAG_IMAGE, image);
                map.put(TAG_APPROVED, approved);


                oslist.add(map);
                list=(ListView)findViewById(R.id.list);
                TextView emptyText = (TextView)findViewById(R.id.empty);
                list.setEmptyView(emptyText);

                //Log.d("TAG_is d first one", TAG_APPROVED + "," + approved);



                adapter = new SimpleAdapter(ListNew.this, oslist,
                        R.layout.list_v,
                        new String[] { TAG_ENAME,TAG_CREATEDBY, TAG_CREATED_AT }, new int[] {
                                R.id.vers,R.id.name, R.id.api});


                list.setAdapter(adapter);

                list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        Intent i = new Intent(ListNew.this, NewEvent.class);
                        i.putExtra("eid", oslist.get(+position).get("eid") ); 
                        i.putExtra("ename", oslist.get(+position).get("ename") );
                        i.putExtra("etype", oslist.get(+position).get("etype") );
                        i.putExtra("edesc", oslist.get(+position).get("edesc") );
                        i.putExtra("esdate", oslist.get(+position).get("esdate") );
                        i.putExtra("eedate", oslist.get(+position).get("eedate") );
                        i.putExtra("estime", oslist.get(+position).get("estime") );
                        i.putExtra("eetime", oslist.get(+position).get("eetime") );
                        i.putExtra("location", oslist.get(+position).get("location") );
                        i.putExtra("created_at", oslist.get(+position).get("created_at") );
                        i.putExtra("edited_at", oslist.get(+position).get("edited_at") );
                        i.putExtra("createdby", oslist.get(+position).get("createdby") );
                        i.putExtra("image",  byteArray);
                        i.putExtra("approved", oslist.get(+position).get("approved") );
                        startActivity(i);

                    }
                });


            }//end if
        } catch (JSONException e) {
            e.printStackTrace();
        }




     }


}
公共类列表新建扩展活动{
列表视图列表;
文本视图eid;
文本视图名称;
TextView edesc;
//按钮Btngetdata;
ArrayList oslist=新的ArrayList();
//获取JSON数组的URL
私有静态字符串url=“somelink”;
//JSON节点名称
私有静态最终字符串标记_OS=“events”;
私有静态最终字符串标记_EID=“EID”;
私有静态最终字符串标记_ENAME=“ENAME”;
私有静态最终字符串标记_ETYPE=“ETYPE”;
私有静态最终字符串标记\u EDESC=“EDESC”;
私有静态最终字符串标记_ESDATE=“ESDATE”;
私有静态最终字符串标记_EEDATE=“EEDATE”;
私有静态最终字符串标记_ESTIME=“ESTIME”;
私有静态最终字符串标记_EETIME=“EETIME”;
私有静态最终字符串TAG_LOCATION=“LOCATION”;
私有静态最终字符串标记_CREATED_AT=“CREATED_AT”;
私有静态最终字符串标记\u EDITED\u AT=“EDITED\u AT”;
私有静态最终字符串标记_CREATEDBY=“CREATEDBY”;
私有静态最终字符串TAG_IMAGE=“IMAGE”;
私有静态最终字符串标记_APPROVED=“APPROVED”;
编辑文本输入搜索;
列表适配器;
公共静态最终字符串表\u EVENT=“EVENT”;
JSONArray事件=null;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//从这里
inputSearch=(EditText)findViewById(R.id.etSearch);
setContentView(R.layout.listnew);
oslist=newarraylist();
新建JSONParse().execute();
}
私有类JSONParse扩展了异步任务{
私人对话;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
eid=(TextView)findViewById(R.id.vers);
ename=(TextView)findViewById(R.id.name);
edesc=(TextView)findViewById(R.id.api);
pDialog=newprogressdialog(ListNew.this);
setMessage(“获取数据…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(真);
pDialog.show();
}
@凌驾
受保护的JSONObject doInBackground(字符串…args){
JSONParser jParser=新的JSONParser();
//从URL获取JSON
JSONObject json=jParser.getJSONFromUrl2(url);
返回json;
}
@凌驾
受保护的void onPostExecute(JSONObject json){
pDialog.disclose();
试一试{
//从URL获取JSON数组
events=json.getJSONArray(TAG_OS);
对于(int i=0;i<EditText
         android:id="@+id/editTxt"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="5dp"
         android:maxLines="1" />
editTxt.addTextChangedListener(new TextWatcher() {

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        adapter.getFilter().filter(s.toString());                           
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {

    }

    @Override
    public void afterTextChanged(Editable s) {
    }
});