Last active
December 18, 2015 10:39
-
-
Save Taishi-Y/5d8a8b745de6629448ed to your computer and use it in GitHub Desktop.
Dialogを使って複数項目から一つの項目を選択する(確認ボタンつき) ref: http://qiita.com/Taishi-Y/items/34975da9d1cfd0f72718
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment