我編輯的是cSipSimple驗證碼:https://code.google.com/p/csipsimple/source/browse/trunk/CSipSimple/src/com/csipsimple/ui/incall/InCallCard.java?spec=svn2170&r=2170runOnUiThread不支持它
,並希望添加這個方法:但是我得到的錯誤
public void pushtotalk2(final View view) {
final boolean on = ((ToggleButton) view).isChecked();
((ToggleButton) view).setEnabled(false);
new Thread(new Runnable() {
@Override
public void run() {
try {
Instrumentation inst = new Instrumentation();
if (on) {
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_NUMPAD_MULTIPLY);
Thread.sleep(500);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_9);
Thread.sleep(500);
runOnUiThread(new Runnable() {
public void run() {
((ToggleButton) view).setBackgroundResource(R.drawable.btn_blue_glossy);
((ToggleButton) view).setEnabled(true);
}
});
} else {
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_POUND);
Thread.sleep(500);
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_9);
Thread.sleep(500);
runOnUiThread(new Runnable() {
public void run() {
((ToggleButton) view).setBackgroundResource(R.drawable.btn_lightblue_glossy);
((ToggleButton) view).setEnabled(true);
}
});
}
} catch (InterruptedException e) {
Log.d(TAG, "Failed to send keycodes: " + e.getMessage());
}
}
}).start();
}
:runOnUiThread(new Runnable(){}) is undefined for the type new Thread(){}
我的理解是活動類有這種方法,但是如何從我的代碼訪問它?
我試圖使一個構造函數和得到這個錯誤:
Implicit super constructor FrameLayout() is undefined. Must explicitly invoke another constructor
關於如何正確地做任何想法?
發佈您的課程代碼已滿。 'runOnUiThread'是活動類的一種方法。所以你需要Activity上下文。 – Raghunandan
@Raghunandan我在鏈接中發佈了完整的代碼。 – Paul
@Tarsem這就是我想要做的,不知道如何。 – Paul