steve Lee
steve Lee

Reputation: 11

android dialog- how to findViewById of my item

My TextView can get message of this dialog as follow:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("your message");
AlertDialog dialog = builder.show();
TextView messageText = (TextView)dialog.findViewById(android.R.id.message);

but, how can I get these string item to TextView ???

final CharSequence[] items = { "String 1", "String 2", "String 3" };
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setItems(items,new DialogInterface.OnClickListener(....
AlertDialog dialog = builder.show();
TextView item = (TextView)dialog.findViewById(android.R.id.?);

please help me~~

Upvotes: 0

Views: 383

Answers (1)

Andrew Brooke
Andrew Brooke

Reputation: 12173

These are list items, not TextViews. You will get the selected item in the callback for the setItems method as such

builder.setItems(items, new DialogInterface.OnClickListener()
    @Override
    public void onClick(DialogInterface dialog, int which) {
        String chosen = items[which].toString();
    }
});

Upvotes: 1

Related Questions