简体   繁体   中英

Creating UI dynamically android

I have the following function

void callDynamicView(){
        String configText="Building Name, S, 10; No: of Floors, I, 3; Area of Plot, D, 10; Location(X), L, 15.3;  Location(Y),  L, 15.3; Photo, P, 10";

    String[] splits = configText.split(";");    
    for(String splitSemi: splits){

        String[] splitsCommas = splitSemi.split(",");
        Toast.makeText(getBaseContext(), splitsCommas[0], Toast.LENGTH_SHORT).show();

        ScrollView sv = new ScrollView(this);
        LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        sv.addView(ll);

        TextView tv = new TextView(this);
        tv.setText(splitsCommas[0]);
        ll.addView(tv);
        this.setContentView(sv);

    }



}

I am creating textview and UI dynamically here. I need to add Building Name, No: of floors, Area of Plot, Location(X), Location(Y) and Photo as text views. In here It only adding last text field Photo. How can I solve this?

void callDynamicView(){
    String configText="Building Name, S, 10; No: of Floors, I, 3; Area of Plot, D, 10; Location(X), L, 15.3;  Location(Y),  L, 15.3; Photo, P, 10";
    ScrollView sv = new ScrollView(this);
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    sv.addView(ll);
String[] splits = configText.split(";");    
for(String splitSemi: splits){

    String[] splitsCommas = splitSemi.split(",");
    Toast.makeText(getBaseContext(), splitsCommas[0], Toast.LENGTH_SHORT).show();



    TextView tv = new TextView(this);
    tv.setText(splitsCommas[0]);
    ll.addView(tv);


}
 this.setContentView(sv);


}

Try this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM