i am designing a app for some quiz.
i need an activity that starts when i press the start button waits for 1 sec displays a red image,watis for 1 sec again displays a yellow face and waits for another sec and displays a green image.
The activity that starts when start quiz is pressed.
public class pgtwo extends Activity {
ImageView rface,yface,gface;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.newpg2);
rface = (ImageView) findViewById(R.id.imageView1);
yface = (ImageView) findViewById(R.id.imageView2);
gface = (ImageView) findViewById(R.id.imageView3);
rface.setVisibility(ImageView.INVISIBLE);
yface.setVisibility(ImageView.INVISIBLE);
gface.setVisibility(ImageView.INVISIBLE);
Thread trd = new Thread(){
@Override
public void run() {
// TODO Auto-generated method stub
try {
sleep(1000);
rface.setVisibility(ImageView.VISIBLE);
sleep(1000);
yface.setVisibility(ImageView.VISIBLE);
sleep(1000);
gface.setVisibility(ImageView.VISIBLE);
} catch (Exception e) {
// TODO: handle exception
}finally{
Intent myIntent = new Intent("com.ak.qmttpack.pgthree");
myIntent.putExtra("pname", pname);
myIntent.putExtra("tabList", tabList);
myIntent.putExtra("order",order);
myIntent.putExtra("noq", noq);
myIntent.putExtra("seq", seq);
startActivity(myIntent);
}
}
};
trd.start();
}
}
i set the images visability as invisable and after waiting for 1 second each image visability becomes visable.
it waits for few seconds and starts the next activity.it dosent work as expected to. why any help plese.
or is there another way to get what i need.
You cannot modify the
UIfrom your thread, and you are getting anExceptionthat you just ignore (which is very bad practice). To modify theUIfrom another thread you should either create aHandlerinside theonCreate()method and then :or use
runOnUiThread()from you thread.