Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我如何在另一个活动(回收者视图)中获得所有价值,这些活动是我选择的_Java_Android - Fatal编程技术网

Java 我如何在另一个活动(回收者视图)中获得所有价值,这些活动是我选择的

Java 我如何在另一个活动(回收者视图)中获得所有价值,这些活动是我选择的,java,android,Java,Android,我需要向第二个活动(使用RecyclerView)发送一个值并将其填充。 例如,在主活动中有一个recyclerView,它可以工作。我想在第二个活动中修改此操作,然后打开第二个活动,我想看到一个填充的回收视图。请救救我 这是我的ArrayList、方法和调用第二个活动 worldList = new ArrayList<>(); worldList.add("cat");//i want to display this word firstly

我需要向第二个活动(使用RecyclerView)发送一个值并将其填充。 例如,在主活动中有一个recyclerView,它可以工作。我想在第二个活动中修改此操作,然后打开第二个活动,我想看到一个填充的回收视图。请救救我

这是我的ArrayList、方法和调用第二个活动

worldList = new ArrayList<>();
    worldList.add("cat");//i want to display this word firstly
    worldList.add("dog");//it after click
    worldList.add("monkey");//after it
    worldList.add("bird");//after it
    worldList.add("fish");//etc
    worldList.add("home");//etc
    worldList.add("car");//etc




public void onClickYes(View view) {
    display.setText(worldList.get(i));
    progress.setText(counter + "");
    wordItems.add(new RecyclerItems(worldList.get(i)));
    builderAdapter();
    if (i < worldList.size()) {
        i++;
        counter++;
    }
    else {
        Toast.makeText(this, "Слова закончились", Toast.LENGTH_SHORT).show();
        i = 0;
    }
}
worldList=newarraylist();
世界名单。添加(“cat”)//我想先显示这个单词
世界名单。添加(“狗”)//点击后点击
世界列表。添加(“猴子”)//之后
世界名单。加上(“鸟”)//之后
世界列表。添加(“鱼”)//等
世界名单。添加(“家”)//等
世界名单。添加(“汽车”)//等
公共void onClickYes(视图){
display.setText(worldList.get(i));
progress.setText(计数器+“”);
添加(新的回收项目(worldList.get(i));
builderAdapter();
如果(i
我的第二项活动

public class YesActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
private RecyclerView.LayoutManager layoutManager;
//ArrayList<String> yesWordList;
///////////////////////////////////////////
final ArrayList<RecyclerItems> wordItems = new ArrayList<>();
///////////////////////////////////////////
//private WordDataBase wordDatabaseForYes;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_yes);

    Bundle extras = getIntent().getExtras();
    String word = null;

    if(extras != null) {
        word = extras.getString("key");
    }

    wordItems.add(new RecyclerItems(word));
    Toast.makeText(this, "Yes", Toast.LENGTH_SHORT).show();

    recyclerView = findViewById(R.id.rvYes);
    recyclerView.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);

    adapter = new RecyclerViewAdapter(wordItems);
    recyclerView.setAdapter(adapter);
    adapter.notifyDataSetChanged();
}
公共类YesActivity扩展了AppCompative活动{
私人回收站;
专用循环视图适配器;
private RecyclerView.LayoutManager LayoutManager;
//ArrayList yesWordList;
///////////////////////////////////////////
final ArrayList wordItems=new ArrayList();
///////////////////////////////////////////
//私有WordDataBase wordDatabaseForYes;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_yes);
Bundle extras=getIntent().getExtras();
字符串字=null;
如果(附加值!=null){
word=extras.getString(“键”);
}
添加(新的回收项目(word));
Toast.makeText(这个“是”,Toast.LENGTH_SHORT).show();
recyclerView=findViewById(R.id.rvYes);
recyclerView.setHasFixedSize(true);
layoutManager=新的LinearLayoutManager(此);
recyclerView.setLayoutManager(layoutManager);
适配器=新的RecycleServiceAdapter(wordItems);
recyclerView.setAdapter(适配器);
adapter.notifyDataSetChanged();
}

}

如果要在两个不同的激活中显示相同的recyclerview(保存数据列表),可以使用公共视图模型。 编写代码以从视图模型中获取数据。(在视图模型中编写getter方法) 然后,您需要做的就是编写代码,在每个活动中创建视图模型的实例,并调用该方法


您可以在RecyclerItems模型中添加一个布尔值,并将所有布尔值初始化为false,然后每当设置此列表中的一项时;将其值转换为true。之后,将arraylist作为parcelable extra传递给新活动,并从arraylist进行筛选,直到为true。或者,您也可以将索引传递给已设置的最后一项的下一个活动。