final CharSequence[] items = {"Now", "Later", "Cancel"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("When you need to Take BackUp?"); builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { // Toast.makeText(getApplicationContext(),items[item],Toast.LENGTH_SHORT).show(); items[0].notify(); items[1].charAt(2); } }); builder.show(); 此對(duì)話框可以完成一些功能,怎樣聲明和定義對(duì)話框?qū)ο竽兀?
2 回答

桃花長(zhǎng)相依
TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊
被選中的item會(huì)被傳遞到onClick方法中,item是onClick方法的一個(gè)參數(shù)。public void onClick(DialogInterface dialog, int item) { switch(item) { case 0: // the first item in the CharSequence[] callUserClickedNow(); break; case 1: // the second item in the CharSequence[] callUserClickedLater(); break; case 2: // the thirditem in the CharSequence[] callUserClickedCancel(); break; } dialog.dismiss(); } 然后,在方法外就可以創(chuàng)建AlertDialog對(duì)象了:private void callUserClickedNow() { // do stuff }
添加回答
舉報(bào)
0/150
提交
取消