為什么點了確認按鈕不會彈出“歡迎大家支持慕課網”
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)+"%");
}
}
2016-10-21
把Toast.makeText(MainActivity.this, "歡迎大家支持慕課網", Toast.LENGTH_SHORT);
Toast.makeText(MainActivity.this, "歡迎大家支持慕課網", Toast.LENGTH_SHORT).show();
2017-03-09
贊同以上說法