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.

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐