Reputation: 1148
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?
Upvotes: 0
Views: 84
Reputation: 1879
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.
Upvotes: 1