2016-07-25 6 views
0

Farbe für alle Textviews in Reihe setzen i ein listadapter wie das Bild erstellt haben unten und die Textviews von hashmap wie dieseWie in listadapter

  HashMap<String, String> kursiShitje = new HashMap<>(); 
      for (int i = 0; i < 6; i++) { 
       kursiShitje.put("text_1", "Shitje"); 
       JSONObject c = values.getJSONObject(i); 
       String name = c.getString(TAG_SELL); 
       kursiShitje.put("text_" + (i + 2), name); 
      } 

Hier bevölkern die listadapter:

ListAdapter adapter = new SimpleAdapter(
       MainActivity.this, kursiKembimit, 
       R.layout.list_rows, new String[]{"text_1", "text_2", "text_3", "text_4", "text_5", "text_6", "text_7"}, 
       new int[]{R.id.text1, R.id.text2, R.id.text3, R.id.text4, R.id.text5, R.id.text6, R.id.text7}) { 

list_rows.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rows" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:paddingBottom="0dp" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp"> 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="180dip" 
     android:layout_height="wrap_content" 
     android:fontFamily="sans-serif-bold" 
     android:gravity="right" 
     android:textColor="@color/white" 
     android:textSize="30sp" 
     android:textStyle="bold"/> 

    <TextView 
     android:id="@+id/text2" 
     android:layout_width="180dip" 
     android:layout_height="wrap_content" 
     android:fontFamily="sans-serif-bold" 
     android:gravity="right" 
     android:textColor="@color/white" 
     android:textSize="30sp" 
     android:textStyle="bold"/> 

    <TextView 
     android:id="@+id/text3" 
     android:layout_width="180dip" 
     android:layout_height="wrap_content" 
     android:fontFamily="sans-serif-bold" 
     android:gravity="right" 
     android:textColor="@color/white" 
     android:textSize="30sp" 
     android:textStyle="bold" 
     /> 

    <TextView 
     android:id="@+id/text4" 
     android:layout_width="180dip" 
     android:layout_height="wrap_content" 
     android:fontFamily="sans-serif-bold" 
     android:gravity="right" 
     android:textColor="@color/white" 
     android:textSize="30sp" 
     android:textStyle="bold" 
     /> 

    <TextView 
     android:id="@+id/text5" 
     android:layout_width="180dip" 
     android:layout_height="wrap_content" 
     android:fontFamily="sans-serif-bold" 
     android:gravity="right" 
     android:textColor="@color/white" 
     android:textSize="30sp" 
     android:textStyle="bold" 
     /> 

    <TextView 
     android:id="@+id/text6" 
     android:layout_width="180dip" 
     android:layout_height="wrap_content" 
     android:fontFamily="sans-serif-bold" 
     android:gravity="right" 
     android:textColor="@color/white" 
     android:textSize="30sp" 
     android:textStyle="bold" 
     /> 

    <TextView 
     android:id="@+id/text7" 
     android:layout_width="180dip" 
     android:layout_height="wrap_content" 
     android:fontFamily="sans-serif-bold" 
     android:gravity="right" 
     android:textColor="@color/white" 
     android:textSize="30sp" 
     android:textStyle="bold" 
     /> 
</LinearLayout> 

Die Frage ist, wie setze ich eine eindeutige Textfarbe für jede Zeile in der Liste. Ich kann Farbe für alle Textansichten mit overriding getView festlegen, aber ich möchte für jede Zeile eine eindeutige Farbe festlegen. Ich kann nicht herausfinden, wie man es löst.

enter image description here

+0

Sie müssen Ihren benutzerdefinierten Adapter verwenden !! –

+0

ich meine baseadapter oder arrayadapter –

+0

show 'R.layout.list_rows' diese XML-Datei? –

Antwort

0

welche Farbe Sie für jeden textView in diesem Layout gesetzt werden die gleiche Farbe in Reihen sein.

Sie haben die White color für alle Textansicht festgelegt verschiedene Farben eingestellt.

versuchen diffrernt Farbe hier android:textColor="@color/BLUE" und überprüfen Sie das Ergebnis.

<TextView 
     android:id="@+id/text4" 
     android:layout_width="180dip" 
     android:layout_height="wrap_content" 
     android:fontFamily="sans-serif-bold" 
     android:gravity="right" 
     android:textColor="@color/white" 
     android:textSize="30sp" 
     android:textStyle="bold" 
     /> 
+0

Ich überschreibe die Ansicht list_rows und setze die Farbe so 'TextView text1 = (TextView) v.findViewById (R.id.text1); text1.setTextColor (Color.parseColor (textColor)); ' Für alle Textansichten. – Aldo

+0

@ Aldo ja das ist auch super option.so ist dein Problem behoben? Wenn mein Beitrag ein wenig hilft, bitte abstimmen und Häkchen danke. –

+0

Ich möchte für jede Zeile eine andere Farbe verwenden, die hashmap ist 1 von 3 hashmaps, die ich erstellt habe, um Daten zu füllen. jetzt kann ich nur eine Farbe für alle Reihen und Textviews einstellen. – Aldo

Verwandte Themen