当点击搜索栏时,下面的值出现

When click searchbar it the value below come up

its image showing value and search bar

it is the image showing when clicking the search bar it will come up the values in list-view

我想知道为什么会发生这种情况以及如何避免这种情况请提前帮助我谢谢

public class ListItem extends AppCompatActivity
{
    ListView listView1;
    ArrayList<String> listproduct;
    ArrayAdapter<String > adapternew;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listitem);
        ActionBar actionBar=getSupportActionBar();
        actionBar.setTitle("Please Select the Item");
      SearchView search=(SearchView)findViewById(R.id.Search);
        ScrollView scroll=(ScrollView)findViewById(R.id.Scroll);
        ListView listView1=(ListView)findViewById(R.id.Listview);
        listproduct=new ArrayList<>();
        listproduct.add("Stove Top Stuffing");
        listproduct.add("Campell's Soup");
        listproduct.add("Tide");
        listproduct.add("Pampers");
        listproduct.add("Pepsi Products");
        listproduct.add("Tang");
        listproduct.add("Top Ramen");
        listproduct.add("Knorr");
        listproduct.add("Palmolive");
        listproduct.add("Scotch-Brite");
        listproduct.add("Bounty Paper Towls");
        listproduct.add("Oreo Cookies");
        listproduct.add("Quaker Oats");
        listproduct.add("Lays Potato Chips");
        adapternew = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,listproduct);
        listView1.setAdapter(adapternew);
        SearchManager manager=(SearchManager)getSystemService(Context.SEARCH_SERVICE);
        search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                search.clearFocus();
            if(listproduct.contains(query))
            {
            adapternew.getFilter().filter(query);
            }
                return false;
            }
            @Override
            public boolean onQueryTextChange(String newText) {
                adapternew.getFilter().filter(newText);
                return false;
            }
             });
          listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int newposition, long id) {
                Toast.makeText(ListItem.this,listproduct.get(newposition)+"",Toast.LENGTH_SHORT).show();
                Intent i=new Intent(ListItem.this,AddOrder.class);
                i.putExtra("position",listproduct.get(newposition));
                //adapternew.notifyDataSetChanged();
                 startActivity(i);
            }
        });



    }
}

这是显示列表视图项的代码,我想知道单击搜索栏时列表视图中的值是否出现

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <SearchView
        android:id="@+id/Search"

        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_alignParentTop="true"
        android:iconifiedByDefault="false"
        android:queryHint="Search Here"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.00" />


    <ScrollView
        android:id="@+id/Scroll"
        android:layout_width="100dp"
        android:layout_height="150dp"
        tools:layout_editor_absoluteX="-8dp"
        tools:layout_editor_absoluteY="396dp">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

        </LinearLayout>
    </ScrollView>

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar2"
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:theme="?attr/actionBarTheme"
        tools:layout_editor_absoluteX="9dp"
        tools:layout_editor_absoluteY="2dp" />

    <ListView
        android:id="@+id/Listview"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_below="@id/Search"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.100"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.200">

    </ListView>
</androidx.constraintlayout.widget.ConstraintLayout>

这是列表视图的xml文件

我认为对于 ConstraintLayout ,您可以使用 app:layout_constraintTop_toBottomOf 将其分配到所需视图下方而不是 layout_below

<ListView
        android:id="@+id/Listview"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.100"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/search" <!-- change here -->
        app:layout_constraintVertical_bias="0.200">

我想这就是你想要的代码,如果我错了请纠正我这里不需要使用 scrollview 因为 ListView 本身是可滚动的并且 LinearLayout with Vertical Orientation 将解决你的问题

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar2"
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme"
    tools:layout_editor_absoluteX="9dp"
    tools:layout_editor_absoluteY="2dp" />


<SearchView
    android:id="@+id/Search"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:layout_alignParentTop="true"
    android:iconifiedByDefault="false"
    android:queryHint="Search Here"/>

<ListView
    android:id="@+id/Listview"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_marginTop="10dp">

</ListView>
</LinearLayout>