本文介紹了Android - 如何隱藏/顯示進(jìn)度條 onclick的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我試圖在單擊按鈕時(shí)顯示進(jìn)度條.當(dāng)我測(cè)試應(yīng)用程序時(shí),它會(huì)強(qiáng)制關(guān)閉/停止.在添加進(jìn)度條代碼之前,我的應(yīng)用程序運(yùn)行良好.
I am trying to show a progressbar when a button is clicked. When i test the app it force closes / stops. My app works fine before the progressbar code is added in.
如果這很重要,我也使用切換按鈕,我希望旋轉(zhuǎn)進(jìn)度條不是對(duì)話框.
also i am using a toggle button if that can matters, and i want the spinning progressbar not a dialog.
有什么幫助嗎?
這是我的代碼:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.buttonFlashlight);
Context context = this;
PackageManager pm = context.getPackageManager();
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.e("err", "Device has no camera!");
return;
}
camera = Camera.open();
final Parameters p = camera.getParameters();
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if (isLighOn) {
progressBar1.setVisibility(View.INVISIBLE);
final MediaPlayer mp1=MediaPlayer.create(getBaseContext(), R.drawable.click);
mp1.start();
Log.i("info", "torch is turn off!");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.stopPreview();
isLighOn = false;
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 1.0f;
getWindow().setAttributes(params);
} else {
progressBar1.setVisibility(View.VISIBLE);
final MediaPlayer mp1=MediaPlayer.create(getBaseContext(), R.drawable.click);
mp1.start();
Log.i("info", "torch is turn on!");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
isLighOn = true;
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0.05f;
getWindow().setAttributes(params);
}
}
});
}
推薦答案
試試下面的代碼...
handler1 = new Handler()
{
@Override
public void handleMessage(Message msg)
{
switch(msg.what)
{
case 1:
static_class.digi_pd = ProgressDialog.show(Create_Digitizing_Job.this, "Loading...", "Please Wait..", true,false);
static_class.digi_pd.setCancelable(false);
break;
case 2:
static_class.digi_pd.dismiss();
break;
}
}
};
thread1 = new Thread()
{
@Override
public void run()
{
try
{
handler1.sendEmptyMessage(1);
// write your code here....
handler1.sendEmptyMessage(3);
handler1.sendEmptyMessage(2);
}
catch (Exception e)
{
Log.w("thread error...",""+e);
//e.printStackTrace();
}
}
};
thread1.start();
這篇關(guān)于Android - 如何隱藏/顯示進(jìn)度條 onclick的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!