Dialogを使って複数項目から一つの項目を選択する(確認ボタンつき) ref: http://qiita.com/Taishi-Y/items/34975da9d1cfd0f72718
public class PostActivity extends AppCompatActivity{
private Button buttonPrefecture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.post_activity);
buttonPrefecture = (Button)findViewById(R.id.button_prefecture);
buttonPrefecture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
choosePrefecture();
}
});
}
public void choosePrefecture(){
final String[] items = {"item_0", "item_1", "item_2"};
int defaultItem = 0; // デフォルトでチェックされているアイテム
new AlertDialog.Builder((this))
.setTitle("Selector")
.setSingleChoiceItems(items, defaultItem, null)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// item_which selected
}
})
.setNegativeButton("Cancel", null)
.show();
}
}