开发者

Android: From StringArray Resources To CharSequence[]

开发者 https://www.devze.com 2023-04-13 00:56 出处:网络
I guess this is a pretty newbie question, but I\'ve spent only 2 weeks on Android. My question is, I have a StringArray created with a reference R.array.NAME

I guess this is a pretty newbie question, but I've spent only 2 weeks on Android.

My question is, I have a StringArray created with a reference R.array.NAME

I want to populate a Dialog full of checkboxes with the values from the StringArray, but it seems I need to convert it to CharSequence[] so I can use: setMultiChoiceItems

I can't find a way to do it.

This is my code (I have to add accept/cancel buttons anyway)

// I want this (subjects variable) to be gotten from my StringArray R.array.NAME

final CharSequence[] subjects = {"Sports", "History", "Maths"};         
final boolean[] states = {false, true, false};    
AlertDia开发者_JS百科log.Builder builder = new AlertDialog.Builder(this);
builder.setMultiChoiceItems(subjects, states, new DialogInterface.OnMultiChoiceClickListener(){
            public void onClick(DialogInterface dialogInterface, int item, boolean state) {
            }
        });

Thanks a lot guys.


From within your Activity call:

String[] subjects = getResources().getStringArray(R.array.NAME);

To obtain the value of the resource.

Hope that helps.


CharSequence[] subjects =getResources().getStringArray(R.array.subjectsName);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号