views:

52

answers:

1
+1  Q: 

view from layout

i came across this http://www.brighthub.com/mobile/google-android/articles/48845.aspx

i understand i can create a view. But i want to define a layout xml and put that into my view. for example in layout i will have a few textviews, i will set value to them dynamically and add them to view and display. is this possible if yes how ? if no whats the alternative ?

+1  A: 

Look at LayoutInflater

Sample:

    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout dialerLayout = (LinearLayout) layoutInflater.inflate(R.layout.phone_dialer, null);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
    dialerLayout.setLayoutParams(params);
    LinearLayout tabDialer = (LinearLayout) findViewById(R.id.tabDialer);
    tabDialer.addView(dialerLayout);

btw: As Bragboy noted above, please accept some of your answers. You currently have an acceptance rate of 0%; otherwise nobody would want to reply to your posts in the future.

Mathias Lin
thank you. i am relatively new to so and did not know, i will keep it mind henceforth. thanks again
mynameisanthpny