[英]android toggle button on click
我是android開發的新手,我想在單擊切換按鈕時設置textview。 單擊切換按鈕時,它正在進行一些冗長的操作,因此我想顯示狀態消息:“服務正在啟動...”
我使用了以下代碼,但是單擊切換按鈕后,沒有任何顯示。 我嘗試將冗長的代碼放入線程中,但是即使在使用thread.join之后,該方法也沒有執行。
@Override
protected void onResume() {
super.onResume();
Reader.getInstance(this,this);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
textView.setVisibility(View.VISIBLE);
Thread t = new Thread(){
public void run(){
startMyService();
}
};
t.start();
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
textView.setVisibility(View.GONE);
}
else {
Thread t = new Thread(){
public void run(){
stopMyService();
}
};
t.start();
}
}
});
}
服務啟動時如何顯示狀態消息?
謝謝
您是否嘗試過通過在textView.setVisibility(View.VISIBLE);
上設置斷點來調試代碼,因此冗長的操作似乎還不足以讓您看到文本在消失之前出現textView.setVisibility(View.VISIBLE);
並在textView.setVisibility(View.GONE);
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.