2012-04-06 5 views
0

私は上部に検索可能なリストビューと検索バーを含むアンドロイドアプリを開発しています。編集用のテキストフィールドに何かを入力すると、展開可能なリストをフィルタしたいと思っています。例えばAndroid - ExpandableListViewはフィルタリング可能です

:I型: "として" 検索バーに - のような>リストがすべき唯一の表示項目: "としてSERT"、 "B としてE"、「C として「as sembling」など

私はインターネットで数時間の検索を行っていますが、この機能を実装することはできません。 だから私は本当に(あなたは私を助けることができると思います。ここでは

は私の拡張可能なリストのアダプタです:

​​3210

そして、ここに私の活動:。ExpandableListViewは、オンラインのMySQLサーバからデータを取得することを 注意理由厥。なぜ私は非同期タスクを使用してい

package activities.shop; 

public class ProductInsert extends BaseActivity { 

    public static final String phpServerConnection = "url-to-php-file"; 
    public static final String phpgetGrocery = "url-to-php-file"; 

    static final int MY_DIALOG_ID = 0; 
    protected static AppPreferences appPrefs; 
    private getGroceryTask ggt = null; 

    private ExpandableListAdapter adapter; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView); 

     listView.setOnChildClickListener(new OnChildClickListener() { 

      public boolean onChildClick(ExpandableListView arg0, View arg1, 
        int arg2, int arg3, long arg4) { 
       Toast.makeText(getBaseContext(), "Child clicked", 
         Toast.LENGTH_LONG).show(); 
       return false; 
      } 
     }); 

     listView.setOnGroupClickListener(new OnGroupClickListener() { 

      public boolean onGroupClick(ExpandableListView arg0, View arg1, 
        int arg2, long arg3) { 
       return false; 
      } 
     }); 

     adapter = new ExpandableListAdapter(this, new ArrayList<String>(), 
       new ArrayList<ArrayList<Product>>()); 

     // Set this blank adapter to the list view 
     listView.setAdapter(adapter); 

     ggt = new getGroceryTask(this); 
     ((getGroceryTask) ggt).execute(); 

    } 

    @Override 
    public int getContentViewId() { 

     return R.layout.productinsert; 
    } 

    @Override 
    protected Dialog onCreateDialog(int id) { 

     ProgressDialog progressDialog = null; 

     switch (id) { 
     case MY_DIALOG_ID: 
      progressDialog = new ProgressDialog(this); 
      progressDialog.setMessage("Aktualisieren..."); 

      break; 
     default: 
      progressDialog = null; 
     } 

     return progressDialog; 
    } 

    final static class getGroceryTask extends 
      SuperAsyncTask<String, String, Void> { 

     ProductInsert activity; 
     InputStream is = null; 
     String result = ""; 

     public getGroceryTask(BaseActivity activity) { 

      super(activity, MY_DIALOG_ID); // change your dialog ID here... 
      this.activity = (ProductInsert) activity; // and your dialog will be 
                 // managed 
                 // automatically! 
     } 

     @Override 
     protected Void doInBackground(String... params) { 

      appPrefs = new AppPreferences(activity); 

      ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
      nameValuePairs.add(new BasicNameValuePair("uEmail", appPrefs 
        .getUserEmail())); 

      try { 
       HttpClient httpclient = new DefaultHttpClient(); 
       HttpPost httppost = new HttpPost(phpgetGrocery); 
       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
       HttpResponse response = httpclient.execute(httppost); 
       HttpEntity entity = response.getEntity(); 
       is = entity.getContent(); 

      } catch (Exception e) { 
       Log.e("log_tag", "Error in http connection " + e.toString()); 
      } 

      // convert response to string 
      try { 
       BufferedReader reader = new BufferedReader(
         new InputStreamReader(is, "UTF-8"), 8); 
       StringBuilder sb = new StringBuilder(); 
       String line = null; 
       while ((line = reader.readLine()) != null) { 
        sb.append(line + "\n"); 
       } 
       is.close(); 
       result = sb.toString(); 

      } catch (Exception e) { 
       Log.e("log_tag", "Error converting result " + e.toString()); 
      } 

      return null; 
     } 

     private Product get(int pid, String pName, String pKat) { 
      return new Product(pid, pName, pKat); 
     } 

     @Override 
     public void onAfterExecute() { 

      try { 

       JSONArray jArray = new JSONArray(result); 
       for (int i = 0; i < jArray.length(); i++) { 

        JSONObject json_data = jArray.getJSONObject(i); 

        activity.adapter.addItem(get(json_data.getInt("pid"), 
          json_data.getString("pName"), 
          json_data.getString("pKat"))); 

       } 

       activity.adapter.notifyDataSetChanged(); 

      } catch (JSONException e) { 
       Log.e("log_tag", "Error parsing datauuuuuu " + e.toString()); 

      } 
     } 

    } 

} 

答えて

0
あなたはむしろので、あなたの拡張可能なリストビューの事前設定項目にAutoCompleteTextViewを使用することができます

拡張可能なリストビューでの問題は、あなたがグループの親に関連付けられている多くの子供を持っている場合、それは時間がかかることである

....スムーズな検索機能があり、上記の機能の代わりにユーザーの選択に基づいてリストを更新できるようにすることができます。上記の機能をエンドユーザーに提供することができます....しかし、あなたの実装では...あなたはonKeyDown機能またはtextvalidation機能を持つ同じAutoCompleteTextViewを使うことができます...

loo kはウィジェットでhttp://developer.android.com/reference/android/widget/AutoCompleteTextView.html

0

を代わりにBaseExpandableListAdapterのCursorTreeAdapterから延びる考えるかもしれません - あなたはgetFilterQueryProviderを上書きすることができ、そのように(そしてあなた自身を提供FilterQueryProvider)を探してください。つまり、MySQL DBの結果をカーソルに変換する必要がありますが、フィルタリング処理を行うともっと簡単になります。

そうでなければ、getFilter()をオーバーライドしてListAdapterに独自のFilterを指定する必要があります。これはあまり変わっていませんが、複雑になりますが、カーソル変換レイヤーを追加する必要はありません。

いずれの場合も、フィルターの編集テキストに独自のtextChangedListenerを追加してフィルターを呼び出します。

+0

['FilterQueryProvider'](http://developers.php)で同様のことをしています(ここではhttp://stackoverflow.com/questions/20585273/cursortreeadapter-with-search-implementation)。 android.com/reference/android/widget/FilterQueryProvider.html)。 [CursorTreeAdapter'](http://developer.android.com/reference/android/widget/CursorTreeAdapter)の子を表す複数のカーソルがあるときに、私が 'runQuery()'で何をすべきか分かりません.html)。これで私を助けてくれますか? – user2784435

関連する問題