Ricky Dam
Ricky Dam

Reputation: 1895

Is there a way to show a specific XML's preview rather than activity_main when building on the device?

I did some research on this topic but could not find my answer.

I am making a news app using RecyclerView and CardView.

I created a layout XML file named "list_row" that includes the CardView. I want to see the preview shown for this XML on my phone when I build it.


Expected


activity_main currently only has a progress bar but when I build, this is the XML that gets loaded.

Actual


Any help on this would be very appreciated!

Upvotes: 0

Views: 99

Answers (3)

Márcio Oliveira
Márcio Oliveira

Reputation: 216

Just change the layout id passed on setContentView() inside onCreate() method of MainActivity.

Upvotes: 0

RobCo
RobCo

Reputation: 6495

You can change the layout in the java code.

  1. Open your MainActivity class. It can be found in 'java>(packagename)>MainActivity.java'
  2. Open it and look for R.layout.activity_main in the onEnable method.
  3. Change that to an other layout, such as R.layout.list_row

Upvotes: 1

Luiz Fernando Salvaterra
Luiz Fernando Salvaterra

Reputation: 4182

You can add this line in your RecyclerView:

   tools:listitem="@layout/list_row"

It will show many layouts in your Preview mode

Upvotes: 0

Related Questions