views:

56

answers:

0

Hi all,

Thanks to help people!

I use an AlertDialog with list (singlechoice->radioButtons). When I choose an item from the list, a toast come and I do a setText of the item on a textView. Everything works when I declare my items like this:

((ImageButton)findViewById(R.id.pickPays)).setOnClickListener(newOnClickListener(){

       public void onClick(View v) {

           final CharSequence[] items = {"United States", "France","Sweden"};
           AlertDialog.Builder builder = newAlertDialog.Builder(Postit.this);
           builder.setTitle("Selectionne tonpays");
           builder.setSingleChoiceItems(items,-1,newDialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int item) {
                   dialog.cancel();
                   Toast.makeText(getApplicationContext(), items[item] ,
                   Toast.LENGTH_LONG).show();
                   ((TextView) findViewById(R.id.paysDisplay)).setText(items[item]);
               }
           });
           AlertDialog alert = builder.create();
           alert.show();

       }
   });

But I want declare my items in a array.xml So I created an array.xml 'pays.xml' and I changed my code like this. The problem is: the application crash when I select an item so when the toast and the setText are called. Do you have any ideas how can I declare my item in the toast and the setText?

((ImageButton)findViewById(R.id.pickPays)).setOnClickListener(newOnClickListener(){

       public void onClick(View v) {


           AlertDialog.Builder builder = newAlertDialog.Builder(Postit.this);
           builder.setTitle("Selectionne tonpays");
                      builder.setSingleChoiceItems(R.array.pays,1,newDialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int item) {
                   dialog.cancel();
                   Toast.makeText(getApplicationContext(), item ,
                   Toast.LENGTH_LONG).show();
                   ((TextView) findViewById(R.id.paysDisplay)).setText(item);
               }
           });
           AlertDialog alert = builder.create();
           alert.show();

       }
   });

Thanks in advance,