天天看點

android 清單dialog,Android Dialog 中的清單顯示選擇

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

final String[] items = new String[]{"蘋果","香蕉","梨子"};

new AlertDialog.Builder(this).setTitle("單選框").setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

switch (which) {

case 0:

Toast.makeText(MainActivity.this, "您選中了:"+items[0], Toast.LENGTH_SHORT).show();

break;

case 1:

Toast.makeText(MainActivity.this, "您選中了:"+items[1], Toast.LENGTH_SHORT).show();

break;

case 2:

Toast.makeText(MainActivity.this, "您選中了:"+items[2], Toast.LENGTH_SHORT).show();

break;

}

}

}).setNegativeButton("取消", null).show();

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here. The action bar will

// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

if (id == R.id.action_settings) {

return true;

}

return super.onOptionsItemSelected(item);

}

}

android 清單dialog,Android Dialog 中的清單顯示選擇