我正在试图找出Android的搜索界面。我的第一个问题与实现listview有关。我在操作栏上使用搜索小部件。这是开场代码:
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);
}
答案 0 :(得分: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>
更多阅读this。
Also, is my implementation of using a Task correct in this and sending the query to php?
不,使用AsyncTask。