I have a little problem here:
I want to make a button in my timer … But I want to put in my view with random position ..
NOTE: I work at Android 2.2 API 8 ..
thanks guys!
Here is my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final int i=1;
Button a = (Button) findViewById(R.id.button1);
a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new CountDownTimer(20000,1000) {
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
//how to create a button here!
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.mainan);
Button btn = new Button(NyaActivity.this);
btn.setId(i+1);
btn.setText("Button"+(i+1));
// i want to set position of button randomly ..
linearLayout.addView(btn);
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
}
}.start();
}
});
}
}
where
widthis the maxValue of the range will give you a random x position, and you can do the same for the height of coursethen you set your LinearLayout.LayoutParams
Voila, random position inside your layout