I’m a first-day android programmer and here is my problem: in my app i have a supporting activity which uses static layout; my activity in onCreate method receives a list of data – how should i embed this data into my existing layout?
So far I’ve tried this code, but it doesn’t shows anything, though there’re no exceptions and there’re few elements, hence loop works:
Activity class:
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.results);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.results, null);
// Find the ScrollView
LinearLayout sv = (LinearLayout) v.findViewById(R.id.lMain);
// getting data here
for (int i = 0; i < recipesList.getId().size(); i++) {
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
// Add text
TextView tv = new TextView(this);
tv.setText("abc");
ll.addView(tv);
sv.addView(ll);
}
results.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/lMain" >
</LinearLayout>
</ScrollView>
Your apporch is wrong. You have to do like this.