I have created a viewflipper vf1 having 9 childview.
onclick method of button B5 create a thread which update the value of mediaplayercurrent position. I want to change child view of a linear layout in auto with the current postion of the mediaplayer, but if statement is not working.
B5.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
if(B5.isChecked()){
new Thread(new Runnable() {
public void run() {
while(mediaPlayer!=null&&j<mediaPlayer.getDuration()){
try {
Thread.sleep(1000);
j= mediaPlayer.getCurrentPosition();
if((j>2000)&&开发者_如何学编程;(j<43000))
{vf1.setDisplayedChild(4);}
if((j>43000)&&(j<72000))
{vf1.setDisplayedChild(1);}
if((j>72000)&&(j<101000))
{vf1.setDisplayedChild(2);}
if((j>101000)&&(j<130000))
{vf1.setDisplayedChild(3);}
if((j>130000)&&(j<160000))
{vf1.setDisplayedChild(4);}
if((j>160000)&&(j<189000))
{vf1.setDisplayedChild(5);}
if((j>189000)&&(j<220000))
{vf1.setDisplayedChild(6);}
if((j>220000)&&(j<251000))
{vf1.setDisplayedChild(7);}
if((j>251000)&&(j<280000))
{vf1.setDisplayedChild(8);}
if((j>280000))
{vf1.setDisplayedChild(0);}
} catch (InterruptedException e) {
return;
} catch (Exception e){
return ;
}
}
}
}).start();
}
}});
i got the clue, i did it by using main runonUIthread
精彩评论