1

I am populating JSON parsed data into Dialog, like this:

String[] colors = new String[] {cArrayList.toString()};
Log.d("colors::-", Arrays.toString(colors));

GETTING

enter image description here

EXPECTED

enter image description here

Oreo
  • 2,586
  • 8
  • 38
  • 63
  • `String[] colors = new String[]{ cArrayList.size() };` What are you attempting to do here? Create an array of Strings of that size or put the size of that arraylist as the first element in the colors array? – Marc Baumbach Sep 19 '15 at 05:06

3 Answers3

2

As per your requirement you can do following if your cArrayList is ArrayList

String[] colors = new String[cArrayList.size()] ;
for(int i=0;i<cArrayList.size();i++)
{
  colors[i]=cArrayList.get(i);
}

Alternatively, you can use the more concise and faster approach:

String[] colors = cArrayList.toArray(new String[cArrayList.size()]);
Clashsoft
  • 11,553
  • 5
  • 40
  • 79
Pavan
  • 5,016
  • 1
  • 26
  • 30
  • getting NPE at this line checkedColors[which] = isChecked; check this: http://pastebin.com/81PBd4Rd – Oreo Sep 19 '15 at 06:47
  • where you defining checkedColors i dint see initialization of checkedColors – Pavan Sep 19 '15 at 06:54
  • global boolean[] checkedColors = null; @Pavan check this : http://pastebin.com/81PBd4Rd – Oreo Sep 19 '15 at 06:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/90093/discussion-between-oreo-and-pavan). – Oreo Sep 19 '15 at 06:55
0

Like in Core Java you convert int[] to List<Integer> same as the code shows below:

    int[] ints = {100,1000,10000};
    List<Integer> ls = new ArrayList<Integer>();
    for (int index = 0; index < ints.length; index++)
    {
        ls.add(ints[index]);
    }

View reference How to convert int[] into List in Java?

Community
  • 1
  • 1
Divyesh Kanzariya
  • 3,629
  • 3
  • 43
  • 44
0

To convert your integer value to a string use:

String.valueOf(insert your integer value here);
sschrass
  • 7,014
  • 6
  • 43
  • 62
akhil batlawala
  • 1,066
  • 1
  • 10
  • 30