3

I have a JSON file that stored in ArrayList using
public static ArrayList<UserData> userDataList = new ArrayList<>();
I also have a class namely as UserData to store multi data in it. Here is the code:

private String sid;
private String symp_name;
private String symp_part;

public UserData(String sid, String symp_name, String symp_part){
    this.sid = sid;
    this.symp_name = symp_name;
    this.symp_part = symp_part;
}

public String getSid() {
    return sid;
}
public String getSymp_name() {
    return symp_name;
}
public String getSymp_part() {
    return symp_part;
}

After requesting the JSON object, I use userDataList.add(data), to stored the data in array.

Now I would like to display symp_name into android setMultipleChoiceItem. I notice that setMultipleChoiceItem accept CharSequence as its parameter. So I have no idea on how to convert the symp_name into char sequence. I try to use this code:

ArrayList<UserData> spart = MainActivity.userDataList;
UserData symp = spart.get(spart.size());
CharSequence[] symptom = symp.getSymp_name();

Unfortunately, it does not working. Any help would be appreciated. Thanks :)

2 Answers 2

2
ArrayList<UserData> spart = MainActivity.userDataList;
UserData symp = spart.get(spart.size());// it will return a single object

CharSequence[] symptom = symp.getSymp_name(); // this will return a single name which you are trying to feed into Array.

You can create a Char array while traversing spart arraylist

CharSequence[] symtoms= new CharSequence[spart.size()] for(int i =0;i<spart.size();i++){ charSequences[i]= spart.get(i). getSymp_name(); }

And now set this charSequence to alertDialog using setMultichoice call. Hope this resolves your issue.

Sign up to request clarification or add additional context in comments.

Comments

0

Visit How to convert a String to CharSequence? This question can let you know how to convert the symp_name into char sequence. If your problem still wasn't solved.I suggest you can debug your project to see variable "symp" is correct or not

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.