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(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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值