編輯:關於Android編程
public class MainActivity extends Activity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button bt1 = (Button) findViewById(R.id.bt1); Button bt2 = (Button) findViewById(R.id.bt2); Button bt3 = (Button) findViewById(R.id.bt3); Button bt4 = (Button) findViewById(R.id.bt4); Button bt5 = (Button) findViewById(R.id.bt5); Button bt6 = (Button) findViewById(R.id.bt6); Button bt7 = (Button) findViewById(R.id.bt7); bt1.setOnClickListener(this); bt2.setOnClickListener(this); bt3.setOnClickListener(this); bt4.setOnClickListener(this); bt5.setOnClickListener(this); bt6.setOnClickListener(this); bt7.setOnClickListener(this); } protected void dialog() { AlertDialog.Builder builder = new Builder(MainActivity.this); builder.setMessage(確認退出嗎?); builder.setTitle(提示); builder.setPositiveButton(確認, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); MainActivity.this.finish(); } }); builder.setNegativeButton(取消, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } protected void dialog2() { Dialog dialog = new AlertDialog.Builder(this) .setIcon(android.R.drawable.btn_star).setTitle(喜好調查) .setMessage(你喜歡周星星的電影嗎?) .setPositiveButton(很喜歡, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, 我很喜歡他的電影。, Toast.LENGTH_LONG).show(); } }).setNegativeButton(不喜歡, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, 我不喜歡他的電影。, Toast.LENGTH_LONG).show(); } }).setNeutralButton(一般, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, 談不上喜歡不喜歡。, Toast.LENGTH_LONG).show(); } }).create(); dialog.show(); } protected void dialog3() { new AlertDialog.Builder(this).setTitle(請輸入) .setIcon(android.R.drawable.ic_dialog_info) .setView(new EditText(this)).setPositiveButton(確定, null) .setNegativeButton(取消, null).show(); } protected void dialog4() { new AlertDialog.Builder(this) .setTitle(復選框) .setMultiChoiceItems(new String[] { Item1, Item2 }, null, null).setPositiveButton(確定, null) .setNegativeButton(取消, null).show(); } protected void dialog5() { new AlertDialog.Builder(this) .setTitle(單選框) .setIcon(android.R.drawable.ic_dialog_info) .setSingleChoiceItems(new String[] { Item1, Item2 }, 0, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setNegativeButton(取消, null).show(); } protected void dialog6() { new AlertDialog.Builder(this).setTitle(列表框) .setItems(new String[] { Item1, Item2 }, null) .setNegativeButton(確定, null).show(); } protected void dialog7() { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.dialog, (ViewGroup) findViewById(R.id.dialog)); new AlertDialog.Builder(this).setTitle(自定義布局).setView(layout) .setPositiveButton(確定, null).setNegativeButton(取消, null) .show(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bt1: dialog(); break; case R.id.bt2: dialog2(); break; case R.id.bt3: dialog3(); break; case R.id.bt4: dialog4(); break; case R.id.bt5: dialog5(); break; case R.id.bt6: dialog6(); break; case R.id.bt7: dialog7(); break; default: break; } } }
本文實例為大家分享了Android實現單項、多項選擇操作的相關代碼,供大家參考,具體內容如下1、單項選擇1.1.布局<?xml version=1.0 en
主要是在原來的基礎上添加了如下功能1.進度圓環的顏色是漸變。 2.添加一個進度標尺,類似與鐘表表盤的樣子,用來顯示刻度。3.添加一個進度指示器,三角形的樣子,用來顯示進
一個項目的需求,之前一篇博客寫過如何生成excel,生成後的excel要發送給用戶(指定郵箱)。奇葩的後台說這個發送也不好實現,要客戶端來做。也就只能做了(又是分分鐘要來
首先,語音合成是指將文本信息轉換成聲音。意思就是將文本轉化為聲音,讓你的應用開口說話。國內在業內比較有名的第三方語音合成平台有百度語音和科大訊飛。本文集成的是百度語音合成