0

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?

2
  • Move ScrollView sv = new ScrollView(this); outside foreach loop then try Commented Mar 5, 2014 at 4:11
  • I have moved the ScrollView sv = new ScrollView(this); outside loop. Now its working Thank you bro. Commented Mar 5, 2014 at 4:14

1 Answer 1

1
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.