Skip to content Skip to sidebar Skip to footer

How To Add View In A Linear Layout Dynamically

I have called a make layout method that takes input label and input public void makeLayout(String label, String inputType) { Toast.makeText(getApplicationContext(), label + '

Solution 1:

First, you have to get familiar with java (in my opinion).

1) declare a linear layout at XML layout. like:

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:id="@+id/AdvancedCatalogContainer"
       ></LinearLayout>

2) Get a referance to that view:

private LinearLayout rootView=findViewById(R.id.AdvancedCatalogContainer);

3) Declare a method like this:

publicvoidfillLayout(LinearLayout root,TextView  v){
  v.setText("your text")
  root.addView(v);
}

4) Call this method in your onCreate method or anywhere in ui thread.

... extends AsycTask<blah,blah,blah>{
onPostExecute(blah){

  for(many times){

    fillLayout(linearLayout,textView);

  }

}

Edit

If you want to show a collection of data like a scrolling list please consider using ListView or RecycleView instead.

Post a Comment for "How To Add View In A Linear Layout Dynamically"