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 回答