tags:

views:

46

answers:

1

I create a program to add check boxes dynamically.But i cant scroll down.I add the code here ,Pls HELP......

package dyntodo.pack;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Button;
import android.widget.TextView;
public class dynact extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView)findViewById(R.id.textview);
final EditText task = (EditText)findViewById(R.id.task);
Button add = (Button)findViewById(R.id.add);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
addTask(task.getText().toString());
}
});
}
public void addTask(String task)
{
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
final CheckBox chk = new CheckBox(this); //Creating checkbox objects…..
chk.setText(task);
layout.addView(chk);
chk.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
chk.setVisibility(5);
}
});
}
}
+2  A: 

what you need to do is wrap all your layout items in a Scroll View. your layout xml (which appears to be main.xml) will look something like this

<?xml ....
<ScrollView 
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" >

   ... other layout elements ...

</ScrollView>

you can also do this with java code by creating a ScrollView object, adding main as a child, and setting your content view to the ScrollView

ScrollView sv = new ScrollView(this);
setContentView(sv);
sv.addView(findViewById(R.id.main));

Let me know if this is helpful or if you have more questions.

mtmurdock
@mtmurdock:thanx............its working
antony
remember to accept answers if they work for you. it gets you points and makes people more willing to help you
mtmurdock