android string数组6,Search value for key in string-array android
I had the same problem.The decision for me was to create many strings in xml-file (not string arrays) and to create String[] array in code. It looks like this:Builder builder = new AlertDialog.Builder
I had the same problem.
The decision for me was to create many strings in xml-file (not string arrays) and to create String[] array in code. It looks like this:
Builder builder = new AlertDialog.Builder(DMCBrowser.this);
builder.setTitle(R.string.title_playlist);
final CharSequence[] items = new CharSequence[] { getResources().getString(R.string.watch_all),
getResources().getString(R.string.select_items) };
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (items[which].equals(getResources().getString(R.string.watch_all))) {
Log.d(TAG, "Watch all");
} else if (items[which].equals(getResources().getString(R.string.select_items))) {
Log.d(TAG, "Select items");
}
}
}).show();
Although it does not look much compact, we can differ one item from another not only by non-understandable identifier like 1 or 2, but by human-readable android R-id. If i would like to change item order, it will be very easy.
更多推荐
所有评论(0)