简体   繁体   English

如何在我选择的另一个活动(回收站视图)中获取所有值

[英]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 的实例并调用该方法。

Here is a useful article series 这是一个有用的文章系列

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在同一活动中添加回收站视图和抽屉布局? - How can I add recycler view and drawer layout in same activity? 如何在其他活动中发送正确答案和所选答案? - How can i send the correct answer and the chosen answer in another activity? 如何在回收站视图中只获取我想要的项目 - how can get only item that I wanted in recycler view 如何获取 Recycler View 中的 TextViews 并将其发送到另一个活动并将其添加到 arraylist 值 - How to get the TextViews inside the Recycler View and send it to another activity and add it to the arraylist values 当我切换到包含回收站视图的另一个活动时,应用程序崩溃 - App crashes when i switch to another activity that contains recycler view 如何在回收站视图中获取所有项目的总数 - How to get total of all items in recycler view 我想将一些物品发送到第二个活动的回收站视图。 我怎么能用房间做到这一点 - I want to send some items to second activity's recycler view. How can I do it with Room 从另一个活动将项目添加到回收者视图 - Add items to recycler view from another activity 通过使用带有 .get(position) 的回收器视图适配器,我无法从回收器视图 java 中的 edittext 获取文本 - I can't get the text from edittext in recycler view java by using recycler view adapter with .get(position) 在项目上单击RecyclerView的监听器 - 如何在回收站视图中使用项目的位置来平滑滚动到另一个列表视图? - On Item Click Listener for RecyclerView - How can I use the position of an item in a recycler view to smoothscroll to another listview?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM