简体   繁体   English

数组资源返回整数

[英]Array resource returning integer

I'm just getting into android app development. 我只是进入android应用程序开发。 I'm trying to find the value of an item in an array resource from the index, but the resource is returning an integer rather than an array. 我正在尝试从索引中找到数组资源中项目的值,但是资源返回的是整数而不是数组。 I have this piece of code: 我有这段代码:

                pop1.setItems(R.array.PopupMenuListItems, new DialogInterface.OnClickListener(){
                public void onClick(DialogInterface dialog, int which ) {
                    Toast.makeText(getBaseContext(), "Selected " + R.array.PopupMenuListItems, Toast.LENGTH_SHORT).show();
                }
            });

and when the Toast message shows, it shows "Selected 2131492864", and I can't index an integer. 当Toast消息显示时,它显示为“ Selected 2131492864”,我无法索引整数。

So, my question is how can I convert R.array.PopupMenuListItems into an array rather than an integer, so I can use R.array.PopupMenuListItems[which]? 因此,我的问题是如何将R.array.PopupMenuListItems转换为数组而不是整数,以便可以使用R.array.PopupMenuListItems [哪个]?

Use getStringArray for getting Array from resources : 使用getStringArray从资源获取Array:

 public void onClick(DialogInterface dialog, int which ) {
 String[] arrAllData = getResources().getStringArray(R.array.PopupMenuListItems2);
  Toast.makeText(getBaseContext(), 
                 "Selected " + arrAllData[which], Toast.LENGTH_SHORT).show();
 }

这样访问

 String[]  mTestArray =  = getResources().getStringArray(R.array.testArray); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM