我想創建一個不需要顯示百分比的進度條。ProgressBar無百分比
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.back:
this.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
finish();
return true;
case R.id.read:
// This is where I would start my spinner....
if(myService.getState() != 3) {
myService.connect(MainMenu.previousDevice, true);
}
readWaves();
return true;
default:
return super.onContextItemSelected(item);
}
}
的微調將停止自己在readWaves()函數...
private void readWaves() {
waveResults = RelayAPIModel.NativeCalls.GetWavesJava(RelayAPIModel.WAVES_V);
// Turn the Spinner off Here.
doOtherThings();
}
我發現噸的代碼遍佈告訴我如何使用線程使用一個進度條,加入進步在xml文件中的bar和許多其他方法。
我認爲做這件事的最好方法是創建一個CustomDialog類來彈出並讓旋轉器旋轉,直到我調用它來結束它。
顯示的第一個答案here是迄今爲止最接近我找到我想要的,但不幸的是他的解決方案不起作用。它不工作的原因是因爲代碼的最後一節:
public MyProgressDialog(Context context) {
super(context, R.style.NewDialog);
}
我使用的是Android 2.3,並且沒有style
的R
屬性。我嘗試自己添加它,並得到一個錯誤。有誰知道如何解決這一問題?
編輯:
這是我使用ProgressDialog
case R.id.read:
pDialog = new ProgressDialog(Waves.this);
pDialog.setTitle("Waves");
pDialog.setMessage("Reading...");
pDialog.show();
if(myService.getState() != 3) {
myService.connect(MainMenu.previousDevice, true);
}
readWaves();
return true;
default:
return super.onContextItemSelected(item);
}
}
private void readWaves() {
if(spinnerChoice == 0) {
Log.i("IN IF", "IN IF");
// Diff Voltage
waveResults = RelayAPIModel.NativeCalls.GetWavesJava(RelayAPIModel.WAVES_V);
} else {
// Current
waveResults = RelayAPIModel.NativeCalls.GetWavesJava(RelayAPIModel.WAVES_I);
}
Log.i("READ WAVES", "After If/Else");
pDialog.dismiss();
/*
你在styles.xml文件中有一個樣式名稱NewDialog ?如果是這樣,你確定你導入了正確的R類嗎? – njzk2
我不知道在哪裏可以找到'styles.xml'文件。我對Android比較陌生,我認爲'R.style.NewDialog'類似於調用'setContentView(R.layout.main)',所以'style'將會是我的項目中的一個目錄。有什麼'styles.xml'文件? – JuiCe
style.xml轉到res/values( - *) – njzk2