2016-04-08 5 views
-2

検索ボックスを持つアンドロイドアプリケーションを開発しています。検索時に検索ボックスの配列リストからすべてのデータを表示する必要があります。データは実際にWebサービスを呼び出した後に来て、outputdatalistというarraylistにデータを格納することができます。アンドロイドでsearchviewを実装し、データベースからデータをリストアウトする方法

これはsearch.xmlです:

<RelativeLayout 
     android:id="@+id/rel2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="30dp"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="60dp" 
      android:id="@+id/search" 
      android:hint="Search by salon name" 
      android:paddingLeft="60dp" 
      android:layout_marginLeft="20dp" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true"/> 
     <Button 
      android:id="@+id/search_logo" 
      android:layout_width="25dp" 
      android:layout_height="18dp" 
      android:layout_alignBaseline="@+id/search" 
      android:layout_alignBottom="@+id/search" 
      android:layout_alignLeft="@+id/search" 
      android:layout_marginLeft="4dp" 
      android:background="@mipmap/search_logo"/> 

Javaファイルには、すべてのデータの持つ配列が含まれています。ここではリストの例を示します。配列にはデータが含まれています。

try { 
    JSONObject jsonObject = new JSONObject(var1); 
    Log.i("jsonObjectttttttttttt", jsonObject.toString()); 
    JSONObject jsonObject1 = jsonObject.getJSONObject("data") 
    Log.i("jsonObjecttttttt1", jsonObject1.toString()); 
    JSONArray jsonArray = jsonObject1.getJSONArray("results"); 
    for (int i = 0; i < jsonArray.length(); i++) { 
      JSONObject child = jsonArray.getJSONObject(i); 
      outputDataList.add(child.getString("name")); 
      Log.i("salonn names",outputDataList.toString());} 

答えて

0

Androidのデベロッパーガイドをご覧ください。それはあなたがしたいことを達成する方法についての良いサンプルを提供します。

http://developer.android.com/guide/topics/search/search-dialog.html

それはあなたが実装しようとしているものに近いのEditTextリストビュー、に似ています。 これには、どのような手順を実行するかの詳細な説明があります。

データを受け取ったとき(JSON形式)には、データを読み込んでデータオブジェクト(ListListなど)に追加するパーサーが必要です。このオブジェクトは、ListViewにバインドするためにアダプタに渡されます。

あなたが達成する必要があることを理解するのに役立ちます。乾杯!

関連する問題