gpt4 book ai didi

java - android 当回车时清除RecyclerView

转载 作者:行者123 更新时间:2023-12-01 17:46:53 25 4
gpt4 key购买 nike

我试图拥有它,以便当我按回车键时,回收器 View 会从旧数据中清除,并抓取并放入并显示新数据。我拥有它,这样无论何时按下输入键,它都会抓取编辑文本中的内容并将其放入随后搜索的变量中。变量正在更新,但保存搜索项的数组未更新。我需要清除该数组吗?我认为要做到这一点,我需要使用 ArrayList 而不是普通数组。这是一个更好的主意吗?

public View.OnKeyListener search = new View.OnKeyListener()
{
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
searchItem = "";

if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER)
{
if(searchItem != searchBar.getText().toString())
{
searchItem = searchBar.getText().toString();
Toast.makeText(imdb_activity.this, "The search is: " + searchItem, Toast.LENGTH_SHORT).show();
Log.d("Android view component", "Enter button was pressed and the value is: " + searchItem);
}
//clear recyclerview?



goGetSearch();
return true;
}
return false;
}
};

最佳答案

您需要将更新后的列表传递给recyclerview,我假设goGetSearch是将参数传递给recyclerview的函数,并且searchItem 是您的列表,所以我希望您了解这个概念,如果我的假设是错误的,您可以编辑它以适合您的情况。

    public View.OnKeyListener search = new View.OnKeyListener()
{
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
searchItem = "";

if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER)
{
if(searchItem != searchBar.getText().toString())
{
searchItem = searchBar.getText().toString();
Toast.makeText(imdb_activity.this, "The search is: " + searchItem,
Toast.LENGTH_SHORT).show();
Log.d("Android view component", "Enter button was pressed and the value
is: " + searchItem);
}
//clear recyclerview?



goGetSearch(searchItem);
return true;
}
return false;
}
};

关于java - android 当回车时清除RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60852687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com