1

Android用の検索インターフェースを見つけようとしています。私の最初の質問は、リストビューを強制することと関係があります。アクションバーの検索ウィジェットを使用しています。開始コードは次のとおりです。

public class SearchableActivity extends ListActivity {

  // class fields

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);

    ListView lv = (ListView) findViewById(android.R.id.list);
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {



        }
    });

    // Get the intent, verify the action and get the query
    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        query = intent.getStringExtra(SearchManager.QUERY);

        ProgressDialog dialog = ProgressDialog.show(
                SearchableActivity.this, "Searching",
                "Searching. Please wait...", true);

        performSearch(query);

        dialog.hide();
        dialog.dismiss();
    }
}

public void performSearch(String query) {
    List<String> dataList = new ArrayList<String>();


    dataList = new ArrayList<String>();
    new task().execute(); // Task calls an HttpPost and opens search through php and populates list through JSON


    ArrayAdapter<String> arr = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, dataList);
    this.setListAdapter(arr);

}
  1. 最初の方法では、ListViewを設定していますが、onClickで実行する必要のあるコードがわかりません。検索結果はどこに行きますか?ユーザーが入力したときに最も近い結果を表示したいと思います。
  2. xml R.id.listをどこに置くかわからない?ドロップダウンとしてウィジェットに組み込まれていますか?(例:Playストアの検索ウィジェット)
  3. また、これでタスクを使用してクエリをphpに送信するという私の実装は正しいですか?
4

1 に答える 1

0
In first method I am setting up a ListView, I am not sure what code I need to do onClick?
Where does the search results go? I'd like to display closest results as the user types.

list itemつまり、行に対してアクションを実行したい場合..のリストがProductあり、OnClick表示したい場合details of your productは、その関連製品の詳細を表示する新しいアクティビティを起動します。

Not sure where to put the xml R.id.list? Is it built in to the widget as a drop down? (e.g. the search widget in Play Store)

あなたのようなものにそれを追加する必要はありませんsearch.xml

    <ListView
  android:id="@android:id/list"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" >
</ListView> 

詳細については、これをお読みください。

Also, is my implementation of using a Task correct in this and sending the query to php?

いいえ、AsyncTaskを使用します。

于 2012-07-17T03:13:02.190 に答える