I want to add views which are created programmatically into a ScrollView
and that ScrollView
is declared in an XML file. How to achieve this?
package com.example.multipleviews;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;
public class MainView extends Activity {
LinearLayout main, child;
ScrollView sc;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_view);
main = (LinearLayout) findViewById(R.id.main);
// Toast.makeText(getApplicationContext(), "hello", 0).show();
view();
}
private void view() {
// TODO Auto-generated method stub
main.removeAllViews();
sc = (ScrollView) findViewById(R.id.sc);
sc.removeAllViews();
child = (LinearLayout) findViewById(R.id.lin);
child.removeAllViews();
for (int i = 0; i < 5; i++) {
Button b = new Button(this);
b.setText("Button "+i);
b.setId(i);
child=(LinearLayout)findViewById(R.id.lin);
child.addView(b);
}
sc.addView(child);
main.addView(sc);
setContentView(main);
}
}
here is my code.....but application does not runs.....