I am presenting user with a alert dialog which contains 2 items, I want to implement an OnClickListener for both items. I am able to set 1 item but when I try to use switch statement, I get this error :
Cannot switch on a value of type CharSequence[]. Only convertible int values or enum constants are permitted
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
final CharSequence[] items = {"Reviews", "More Info"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Please Select an Option");
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
switch (items){
case 1 :
//do something
case 2:
Intent intent = new Intent (MyActivity.this, WebViewActivity.class);
MyActivity.this.startActivity(intent);
}
});
AlertDialog alert = builder.create();
alert.show();