2.メソッド実装ダイアログ
2199 ワード
Spinnerの代わりにボタンを使って、ポップアップのダイアログボックス、スクリーンショットとコードは添付ファイルを参照してください!
spinnerでダイアログを実装する
ボタンで実現
spinnerでダイアログを実装する
public class SpinnerUseInArea extends Activity {
Spinner mySpinner;
private static final String[] countriesStr = { "111", "222", "333", "444" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mySpinner = (Spinner) findViewById(R.id.mySpinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, countriesStr);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
mySpinner.setAdapter(adapter);
}
}
ボタンで実現
public class EX03_12 extends Activity
{
private Button mButton1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton1 = (Button) findViewById(R.id.myButton1);
mButton1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
new AlertDialog.Builder(EX03_12.this)
// .setTitle("niaho")
.setItems(R.array.select_dialog_items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
/* User clicked so do some stuff */
/* String[] items = getResources().getStringArray(R.array.select_dialog_items);
new AlertDialog.Builder(EX03_12.this)
.setMessage("You selected: " + which + " , " + items[which])
.show();*/
}
}).show();
}
});
}
}