为什么点了确认按钮不会弹出“欢迎大家支持慕课网”
package com.example.progressbar;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
private ProgressBar progressBar;
private Button add;
private Button jian;
private Button chong;
private TextView text;
private ProgressDialog progressDialog;
private Button show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.zyq);
setProgressBarIndeterminate(true);
setProgressBarIndeterminateVisibility(false);
init();
}
private void init() {
// TODO Auto-generated method stub
progressBar=(ProgressBar) findViewById(R.id.hon);
add=(Button) findViewById(R.id.add);
jian=(Button) findViewById(R.id.jian);
chong=(Button) findViewById(R.id.chong);
text=(TextView) findViewById(R.id.text);
show=(Button) findViewById(R.id.show);
show.setOnClickListener(this);
int first = progressBar.getProgress();
int second = progressBar.getSecondaryProgress();
int max = progressBar.getMax();
text.setText("第一进度:"+(int)(first/(float)max*100)+"% 第二进度:"+(int)(second/(float)max*100)+"%");
add.setOnClickListener(this);
jian.setOnClickListener(this);
chong.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.add:{
progressBar.incrementProgressBy(5);
progressBar.incrementSecondaryProgressBy(5);
break;
}
case R.id.jian:{
progressBar.incrementProgressBy(-5);
progressBar.incrementSecondaryProgressBy(-5);
break;
}
case R.id.chong:{
progressBar.setProgress(50);
progressBar.setSecondaryProgress(80);
break;
}
case R.id.show:{
progressDialog=new ProgressDialog(MainActivity.this );
progressDialog.setProgressStyle(progressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle("慕课网");
progressDialog.setMessage("欢迎大家支持慕课网");
progressDialog.setIcon(R.drawable.ic_launcher);
progressDialog.setMax(100);
progressDialog.incrementProgressBy(60);
progressDialog.setIndeterminate(false);
progressDialog.setButton(progressDialog.BUTTON_POSITIVE, "确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "欢迎大家支持慕课网", Toast.LENGTH_SHORT);
}
});
progressDialog.setCancelable(true);
progressDialog.show();
break;
}
}
text.setText("第一进度:"+(int)(progressBar.getProgress()/(float)progressBar.getMax()*100)+"% 第二进度:"+(int)(progressBar.getSecondaryProgress()/(float)progressBar.getMax()*100)+"%");
}
}