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