有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在安卓中实现searchview并从数据库中列出数据

我正在开发一个安卓应用程序,它有一个搜索框,我需要在搜索时显示搜索框中数组列表中的所有数据。数据实际上是在调用Web服务之后出现的,可以将数据存储在名为outputdatalist的arraylist中

这是搜索。xml:

 <RelativeLayout
        安卓:id="@+id/rel2"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_marginBottom="30dp">
        <EditText
            安卓:layout_width="match_parent"
            安卓:layout_height="60dp"
            安卓:id="@+id/search"
            安卓:hint="Search by salon name"
            安卓:paddingLeft="60dp"
            安卓:layout_marginLeft="20dp"
            安卓:layout_alignParentTop="true"
            安卓:layout_centerHorizontal="true"/>
        <Button
            安卓:id="@+id/search_logo"
            安卓:layout_width="25dp"
            安卓:layout_height="18dp"
            安卓:layout_alignBaseline="@+id/search"
            安卓:layout_alignBottom="@+id/search"
            安卓:layout_alignLeft="@+id/search"
            安卓:layout_marginLeft="4dp"
            安卓:background="@mipmap/search_logo"/>

Java文件包含包含所有数据的数组

try {
     JSONObject jsonObject = new JSONObject(var1);
     Log.i("jsonObjectttttttttttt", jsonObject.toString());
     JSONObject jsonObject1 = jsonObject.getJSONObject("data")
     Log.i("jsonObjecttttttt1", jsonObject1.toString());
     JSONArray jsonArray = jsonObject1.getJSONArray("results");
     for (int i = 0; i < jsonArray.length(); i++) {
           JSONObject child = jsonArray.getJSONObject(i);
            outputDataList.add(child.getString("name"));
            Log.i("salonn names",outputDataList.toString());}

共 (1) 个答案

  1. # 1 楼答案

    <>你可以考虑看Android的开发者指南。它提供了一个很好的示例,说明如何实现您想要做的事情

    http://developer.android.com/guide/topics/search/search-dialog.html

    它类似于编辑文本列表视图,接近您试图实现的内容。 它详细说明了要执行的步骤

    当您接收到数据(JSON格式)时,您需要一个解析器来读取数据并将其格式化,然后将其添加到一个数据对象(例如ArrayList)中,该数据对象将被传递到适配器以与ListView绑定

    希望这能帮助你理解你需要实现的目标。干杯