1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
package com.tratak.droid.alertspin;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
public class AlertSpinTest extends Activity
implements View.OnClickListener {
Button btOpenDiag;
static final int DIAG_SPINNER = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btOpenDiag = (Button)findViewById(R.id.alertbutton);
btOpenDiag.setOnClickListener(this);
}
public void onClick(View view) {
if (view == btOpenDiag) {
showDialog(DIAG_SPINNER);
}
}
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIAG_SPINNER:
String[] items = {"tic", "tac", "toe"};
LayoutInflater factory = LayoutInflater.from(this);
final View diagView = factory.inflate(R.layout.dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setTitle("Faite votre choix")
.setView(diagView)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* l'utilisateur a clique sur Ok */
}
});
Spinner spin = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, items);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
return builder.create();
}
return null;
}
} |
Partager