How to Run a Recicle View on Other Activities

0

How do I put a recycle view or a list view into some other activity?

Example: I created a project with name X in it as soon as I put the layout as Empty activity and so it generates an activity_main layout and a standard MainActivity class, dai blz if I create other example layouts b activity and class B, everything that squeezes into class B so that it shows in layout B does not appear. What should I do?

Look at 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);
    }
}
    
asked by anonymous 12.09.2017 / 15:46

1 answer

0
setContentView(R.layout.activity_main);

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

I hope I have helped

Please put the class b code in the question, this will make it much easier

    
13.09.2017 / 03:35