0

A basically question-> because i cant find a answer since a lot of days... if i have a for loop (10 times) and each output is a different string. How can i make a specific String-output colored?

for(int i=0; i< posts.length();i++ ) {
        JSONObject post = posts.optJSONObject(i);
        this.title = post.optString("title");

        blogTitles[i] = title;
        }

Sure i can sort the specific blogtitles[i] by code

title.toLowerCase().contains("neune")

but if i try to give it the new layout, he layout is used for all (10x) outputs any can help?

Thx for answer now i changed to

JSONObject post = posts.getJSONObject(i);
            this.title = post.getString("title");

but still all outputs are black and in layout "android.R.layout.simple_list_item_1"

complete code

for(int i=0; i< posts.length();i++ ) {
            JSONObject post = posts.getJSONObject(i);
            this.title = post.getString("title");


            arrayAdapter1 = new ArrayAdapter(MainActivity.this, R.layout.mytextview, blogTitles1);
            arrayAdapter2 = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, blogTitles2);



            if (title.toLowerCase().contains("neune") && title.contains(this.id.toLowerCase())) {         //ean nicht neu (!kontrolliert!)



               //     listView.setTheme(R.layout.mytextview);
                    listView.setAdapter(arrayAdapter1);
                    String title2= title.replace("neune*", "");
                    String title3 = title2.replace(this.id + ",", "-eigene Bewertung");
                    blogTitles1[i] = title3;
                    bewertungseingabe.setVisibility(View.VISIBLE);
                    bewertungsueberschrift.setVisibility(View.VISIBLE);
                    bewertbutton.setVisibility(View.VISIBLE);
                    editBtn.setVisibility(View.VISIBLE);

            }

            if (title.toLowerCase().contains("neune") ) {
                listView.setAdapter(arrayAdapter2);
                    String title2= title.replace("neune*", "error!!!!");
                    String title3 = title2.replace(this.id + ",", "*");
                    blogTitles2[i] = title3;

            }

            if (title.toLowerCase().contains("neuja")&& title.contains(this.id.toLowerCase())) {            //ean neu (!noch nicht kontrolliert!)

                    String title2= title.replace("neuja*", "");
                    String title3 = title2.replace(this.id + ",", "-eigene Bewertung");
                    blogTitles1[i] = title3;

            }
            if (title.toLowerCase().contains("neuja") ) {
                    blogTitles2[i] = "Dieser Artikel ist in Ordnung!";

            }

            if (title.toLowerCase().contains("ganz")) {          //ean neu (!noch nicht kontrolliert!)
                blogTitles2[i] = "Du hast uns so eben eine neue EAN mitgeteilt" +
                        "füge eine Bezeichnung und Bewertung hinzu, wenn du magst...";
              //  zaehler[i]=blogTitles[i];

            }


        }

only the second layout is used.... i guess it is because "title.toLowerCase().contains("neune") && title.contains(this.id.toLowerCase())" is true and "title.toLowerCase().contains("neune")" is true.... it "must" be this way, because each (i)output should be evaluated

Newbster
  • 1
  • 6

2 Answers2

0

Parse Json as follows.

JSONObject post = posts.getJSONObject(i);
this.title = post.getString("title");
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
Nikhil
  • 3,711
  • 8
  • 32
  • 43
  • thanks but it still nord work... all looking in layout "android.R.layout.simple_list_item_1" (watch main asking for the update of code) – Newbster Sep 03 '16 at 11:25
0

Edit:
String getStr;

    for(int i=0; i< posts.length();i++ ) {
    JSONObject post = posts.optJSONObject(i);
    this.title = post.optString("title");

     blogTitles[i] = title;

       getStr = blogTitles[i];

     if("neune".equals(getStr)){

    SpannableStringBuilder builder = new SpannableStringBuilder();

    SpannableString redSpannable= new SpannableString(getStr);
     redSpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, getStr, 0);
     builder.append(redSpannable);


    }
Stephen
  • 9,899
  • 16
  • 90
  • 137
  • i cant use equals because title is a packet of informations like "neune, blabla, more of bla bla, android id, bla" at this packet it should find "neune" sort it specify with the help of this word and use the other subsets later.... but i will try the spannableStringbulder... Need some time to think about this part – Newbster Sep 03 '16 at 11:35
  • i can not use red.length() "cannot resolve symbole 'red' " – Newbster Sep 03 '16 at 11:38
  • its not working failures.... "getstring" is a String right? than i cannott use it at "redSpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, getStr, 0);" a int is required and otherwise i cannot use equals see further post ->the input string is a packet... – Newbster Sep 03 '16 at 11:58