為什么沒有提示錯誤,可是運行說有錯誤不能運行,老師您可以幫我看看那有錯嗎
case R.id.add:{
break;
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:orientation="vertical" >
? ? <ProgressBar
? ? ? ? android:id="@+id/progressBar1"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content" />
? ? <ProgressBar
? ? ? ? android:id="@+id/horiz"
? ? ? ? android:max="100"
? ? ? ? android:progress="50"
? ? ? ? android:secondaryProgress="80"
? ? ? ? style="?android:attr/progressBarStyleHorizontal"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content" />
? ? <Button
? ? ? ? android:id="@+id/add"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="@string/add" />
? ? <Button
? ? ? ? android:id="@+id/reduce"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="@string/reduce" />
? ? <Button
? ? ? ? android:id="@+id/reset"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="@string/reset" />
? ? <TextView
? ? ? ? android:id="@+id/text"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="TextView" />
</LinearLayout>
為什么沒有提示錯誤,可是運行說有錯誤不能運行,老師您可以幫我看看那有錯嗎
2016-08-27
你string.xml文件里有沒有賦值
2016-05-26
package com.example.android_progressbar;
import android.support.v7.app.ActionBarActivity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebView.FindListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements OnClickListener{
private ProgressBar progress;
private Button add;
private Button reduce;
private Button reset;
private TextView text;
private ProgressDialog prodialog;
private Button show;
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ?
? ? ? ? //啟用窗口特征,啟用帶進度和不帶進度的進度條
? ? ? ? requestWindowFeature(Window.FEATURE_PROGRESS);
? ? ? ? requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
? ? ? ? setContentView(R.layout.main);
? ? ? ? //顯示兩種進度條
? ? ? ? setProgressBarVisibility(true);
? ? ? ? setProgressBarIndeterminateVisibility(true);
? ? ? ? //max1000
? ? ? ? setProgress(999);
? ? ? ? init();
? ? }
private void init() {
// TODO Auto-generated method stub
progress=(ProgressBar) findViewById(R.id.horiz);
add=(Button) findViewById(R.id.add);
reduce=(Button) findViewById(R.id.reduce);
reset=(Button) findViewById(R.id.reset);
text=(TextView) findViewById(R.id.text);
show=(Button) findViewById(R.id.show);
show.setOnClickListener(this);
//獲取第一進度條的進度
int first=progress.getProgress();
//獲取第二進度條的進度
int second=progress.getSecondaryProgress();
//獲取進度條的最大進度
int max=progress.getMax();
text.setText("第一進度的百分比:"+(int)(first/(float)max*100)+"% 第二進度的百分比:"+(int)(second/(float)max*100)+"%");
add.setOnClickListener(this);
reduce.setOnClickListener(this);
reset.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.add:{
//增加第一進度和第二進度10個刻度
progress.incrementProgressBy(10);
progress.incrementSecondaryProgressBy(10);
break;
}
case R.id.reduce:{
progress.incrementProgressBy(-10);
progress.incrementSecondaryProgressBy(-10);
break;
}
case R.id.reset:{
progress.setProgress(50);
progress.setSecondaryProgress(80);
break;
}
case R.id.show:{
/*
* 頁面顯示功能
*/
//新建ProgressDialog對象
prodialog=new ProgressDialog(MainActivity.this);
//設置顯示風格
prodialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//設置標題
prodialog.setTitle("慕課網");
//設置對話框里的文字信息
prodialog.setMessage("歡迎大家支持慕課網");
//設置圖標
prodialog.setIcon(R.drawable.ic_launcher);
/*
* 設定關于ProgressBar的一些屬性
*/
//設定最大進度
prodialog.setMax(100);
//設定初始化已經增長到的進度
prodialog.incrementProgressBy(50);
//進度條是明顯顯示進度的
prodialog.setIndeterminate(false);
/*
* 設定一個確定按鈕
*/
prodialog.setButton(DialogInterface.BUTTON_POSITIVE, "確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "歡迎支持慕課網",Toast.LENGTH_SHORT).show();
}
});
//是否可以通過返回按鈕退出對話框
prodialog.setCancelable(true);
//顯示ProgressDialog
prodialog.show();
break;
}
}
text.setText("第一進度的百分比:"+(int)(progress.getProgress()/(float)progress.getMax()*100)+"% 第二進度的百分比:"+(int)(progress.getSecondaryProgress()/(float)progress.getMax()*100)+"%");
}
? ?
}
還是不行,不是break的問題