十年網(wǎng)站開(kāi)發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無(wú)憂售后,網(wǎng)站問(wèn)題一站解決
這篇文章主要介紹了Android中如何對(duì)AlertDialog進(jìn)行操作的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇Android中如何對(duì)AlertDialog進(jìn)行操作文章都會(huì)有所收獲,下面我們一起來(lái)看看吧。
Android AlertDialog代碼示例:
package maximyudin.AlertDialogBuilderSample; import android.app.Activity; import android.os.Bundle; import android.widget.Button; import android.view.View; import android.app.AlertDialog; import android.content.DialogInterface; public class AlertDialogBuilderSample extends Activity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); final Button btnQuit = (Button) findViewById(R.id.btnQuit); btnQuit.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { new AlertDialog.Builder(AlertDialogBuilderSample.this) .setTitle(“Question”) .setMessage(“Are you sure that you want to quit?”) .setIcon(R.drawable.question) .setPositiveButton(“Yes”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setResult(RESULT_OK); finish(); } }) .setNegativeButton(“No”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }) .show(); } }); final Button btnTravels = (Button) findViewById(R.id.btnTravels); btnTravels.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { new AlertDialog.Builder(AlertDialogBuilderSample.this) .setTitle(“I want to go to”) .setItems(R.array.items_indide_dialog, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichcountry) { String[] travelcountries = getResources().getStringArray(R.array.items_indide_dialog); new AlertDialog.Builder(AlertDialogBuilderSample.this) .setMessage(“I’m going to “ + travelcountries[whichcountry]) .setNeutralButton(“Cancel”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }) .show(); } }) .show(); } }); } }
關(guān)于“Android中如何對(duì)AlertDialog進(jìn)行操作”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“Android中如何對(duì)AlertDialog進(jìn)行操作”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。