0

I'm a bit stuck here. I have a graph but next to the graph I would love to put a textview. The textView should get my records straight from the database and add a colour code to it. (For now a simple for loop will do)

I've got to the point that the pie chart gets drawn and a textview next to the pie chart shows all strings printed (which is now test + the number from the array)

protected void createPiechart(){
        Number[] seriesOfNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        int teller = 0, teller2 = 0;
        String text= "";
        PieGraph pg = (PieGraph) findViewById(R.id.piegraph);

        for (teller = 0; teller < seriesOfNumbers.length;) {
            //Random colors in the whole range
            Random randomFullRange = new Random();
            int color = Color.argb(255, randomFullRange.nextInt(256), randomFullRange.nextInt(256), randomFullRange.nextInt(256));
            teller2 = 100 + (15 * teller);
            seriesOfNumbers[teller] = teller;
            PieSlice slice = new PieSlice();

            //Random colors only in green tints.
            //Random rnd = new Random();
            //int color = Color.argb(255, 0, teller2, 0);
            slice.setColor(color);
            slice.setValue(teller);
            slice.setTitle("test");
            pg.addSlice(slice);


            text += "test " + teller + "\n";
            teller++;
        }
        TextView textPieGraph = (TextView) findViewById(R.id.textPieGraph);
        textPieGraph.setText(text);
    }

Now I would like to add the colour that the pieslice has in the textview in some sort of bitmap (lets say 20px*20px) Which would give Bitmap Categoryname1 Bitmap2 Categoryname2 ... etc etc.

Now how could I add bitmaps to it dynamically with the same colours of my int color value? I'd love a colour coded list with the text.

Thanks Yenthe

Claire Nielsen
  • 1,881
  • 1
  • 14
  • 31
Yenthe
  • 2,313
  • 5
  • 26
  • 46

1 Answers1

0

You could set the background of the textview to the color or add a bitmap behind the text.

textPieGraph.setBackgroundColor(Color.blahblah);  

If you wanted it beside it (which might be easier for the user) in a smaller form you could add a linearlayout horizontal around the textview and put a small view beside it and color the background in it. This way there could be the color square beside the text.

a54studio
  • 965
  • 11
  • 11
  • I cant set the textfields colour to another colour because the for lus would only keep the last colour. And every record should have another colour.. Could you give an example on how to add the bitmaps in a for lus though? That would be a great solution. – Yenthe Nov 05 '13 at 09:39
  • Your TextView doesn't appear to be in the loop, aren't you only setting one thing to it? This would be the last color. – a54studio Nov 05 '13 at 18:53
  • I add the text by adding to the variable text += "test " + teller + "\n"; and then place it in the TextView. But it only gets the last colour yes, since thats the last cycle of the for lus – Yenthe Nov 07 '13 at 13:45
  • Why not just use a ListView or a LinearLayout with TextView to show the names. Showing them by just going to the next line doesn't make sense if you want to put something beside them. The way you are doing it you could change your text color, but adding in something like an index image would be wayyyy more work than just doing it another way! – a54studio Nov 08 '13 at 13:55
  • Would I be able to change the colour of every line / comment in the for lus then? – Yenthe Nov 08 '13 at 16:22
  • 1
    Yes, you'd either set it in a String or could use a Spannable. See here.. http://stackoverflow.com/questions/6094315/single-textview-with-two-different-colored-text – a54studio Nov 08 '13 at 19:33
  • Just what I needed! Thank you digiholic :) – Yenthe Nov 09 '13 at 14:39