How to run a Recicle view on other activitys

Asked

Viewed 37 times

0

How do I place a recicle view or a list view in some other Ctivity ?

Example: I created a project with name X dai in it so I put the layout as Empty Activity and such it generates me an activity_main layout and a standard Mainactivity class , dai blz if I create other layouts example b Activity and class B , everything I run in class B to show itself in layout B does not appear . What should I do ?

Look at the main:

public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private MyAdapter adapter;
    private List<RecyclerItem> listItems;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

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

        listItems = new ArrayList<>();
        //Generate sample data

        for (int i = 0; i<10; i++) {
            listItems.add(new RecyclerItem("Item " + (i + 1), "teste " + (i+1)));
        }

        //Set adapter
        adapter = new MyAdapter(listItems, this);
        recyclerView.setAdapter(adapter);
    }
}

1 answer

0

setContentView(R.layout.activity_main);

This line arrow the content view in xml activity_main, make sure your code of class b is set in the correct xml (R.layout.activity_b, for example) Another error may be if the references are with the wrong name, for example you have placed an Edittext with the id et1 and called the id et2 that is in another layout

I hope I’ve helped

Please put the code of class b in the question, it will make it very easy

  • William , thanks for the help looks at the other code .

  • the man code is the main class so I created another Activity with the name start public class extends Appcompatactivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_start); } } then it takes to this code of this screen with name start on it that had to show the recycle , so that from there on the first screen has a button that takes this second , only that on this second screen shows blank does not show the recycle view

Browser other questions tagged

You are not signed in. Login or sign up in order to post.