This is the top half of the class that hosts the dialog.
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MovieAdd extends Activity {
private EditText mTitleText;
private Button mSavebutton;
private Long mRowId;
private MyMoviesDBAdapter mDbHelper;
private String genrename;
private TextView mGenretext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
mDbHelper = new MyMoviesDBAdapter(this);
setContentView(R.layout.add_movie_dialog);
mTitleText = (EditText) findViewById(R.id.mMovietitle);
mGenretext = (TextView) findViewById(R.id.genre_text);
mSavebutton = (Button) findViewById(R.id.mSavebutton);
mRowId = savedInstanceState != null ? savedInstanceState.getLong(MyMoviesDBAdapter.KEY_ROWID)
: null;
registerButtonListeners();
onCreateDialog(savedInstanceState);
}
the problem is that when I use this code, the TextView is always set to "Thriller" the "which" variable seems to always be initializing to 14. I'm not even sure this is the best method to achieve what I am trying to do as later, after the dialog is closed, the "genrename" variable is then passed into a database.
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(MovieAdd.this);
builder.setTitle(R.string.select_genre);
builder.setItems(R.array.genres, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
switch(which) {
case 0:
genrename = "Action";
case 1:
genrename = "Anime";
case 2:
genrename = "Childrens";
case 3:
genrename = "Classics";
case 4:
genrename = "Comedy";
case 5:
genrename = "Cult";
case 6:
genrename = "Documentary";
case 7:
genrename = "Drama";
case 8:
genrename = "Foreign";
case 9:
genrename = "Horror";
case 10:
genrename = "Music";
case 11:
genrename = "Romance";
case 12:
genrename = "Sci-fi";
case 13:
genrename = "Sports";
case 14:
genrename = "Thriller";
}
mGenretext.setText(genrename);
}
});
return builder.show();
}