[英]How can i get all valuese in an another Activity (Recycler View), whose were chosen by me
I need to send a value to Second Activity(with RecyclerView) and full it.我需要向第二个活动(使用 RecyclerView)发送一个值并将其填满。 For example, there is a recyclerView in Main Activity and it works.
例如,在 Main Activity 中有一个 recyclerView,它可以工作。 I want to revise this action in second Activity and then i open a Second Activity i want to see there a filled recyclerView.
我想在第二个活动中修改这个动作,然后我打开一个第二个活动我想看到一个填充的 recyclerView。 Please.
请。 Help me!
帮我!
This is my ArrayList,method and call the second activity.这是我的 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;
}
}
My Second Activity我的第二个活动
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();
}
} }
If you want to display the same recyclerview(save list of data) in two different activates, you could use a common View model.如果您想在两个不同的激活中显示相同的回收视图(保存数据列表),您可以使用通用视图 model。 Write codes to get the data from the view model.
编写代码以从视图 model 获取数据。 (write a getter method in the view model) Then all you need to do is write codes to create an instance of view model in each activity and call the that method.
(在视图模型中编写一个 getter 方法)然后您需要做的就是编写代码以在每个活动中创建视图 model 的实例并调用该方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.