Pregunta

so i have this class called book. this book is both a java class and an xml file for the layout. i then have a class/xml file called book_shelf. in my book_shelf xml file i have a view called book1.

public class book_shelf extends Activity {
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.mainmenu, menu);

        book MyBook = new book();
        final View book1 = (View) findViewById(R.id.book1);
        book1.(load my book xml layout in this view)
        return true;

    }

}

i want to load a book layout into the view in my bookshelf frame. Please and thank you.

¿Fue útil?

Solución

You need to use inflator to inflat the desired Layout and than add the layout in the view. E.g.

book MyBook = new book();
final View book1 = (View) findViewById(R.id.book1);

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

//assuming R.layout.book your book xml
View bookView = inflater.inflate(R.layout.book, null);

//Add bookView layout to your book1.
book1.addView(bookView)

Edited: Try this

final View book1 = (View) findViewById(R.id.book1);
((ViewGroup) book1).addView(bookView, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top