Sunday, 11 August 2013

Android Get value from String array

Android Get value from String array

I simply want a dialog box to appear showing the values in the array. Then
on the button click, I want to get the value of the selected radio button
and show it in a toast. Thanks for the answer in advance! It is greatly
appreciated.
package com.example.moredialogs;
import java.lang.reflect.Array;
import java.util.ArrayList;
import android.R.string;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Menu;
import android.widget.Toast;
public class Next extends Activity {
private Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
mContext = this;
AlertDialog.Builder builder =
new AlertDialog.Builder(mContext);
builder.setTitle("Show dialog");
final CharSequence[] choiceList =
{"Coke", "Pepsi" , "Sprite" , "Seven Up" };
int selected = 0;
builder.setSingleChoiceItems(choiceList, selected,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
// This is where I want the value to be selected
}
});
builder.setPositiveButton("Sounds Good", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// User clicked OK, so save the mSelectedItems results
somewhere
// or return them to the component that opened the dialog
// On button click I want the selected Item to go in here
}
});
builder.show();
}
}

No comments:

Post a Comment