【问题标题】:ListView and SearchActivity for AndroidAndroid 的 ListView 和 SearchActivity
【发布时间】:2012-07-17 01:45:51
【问题描述】:

我正在尝试找出适用于 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 的实现是否正确?

【问题讨论】:

    标签: android listview search widget


    【解决方案1】:
    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 执行操作,即一行..就像您有一个ProductOnClick 的列表一样,您想显示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 like..

        <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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多