2013-05-15 3 views
0

Я хочу изменить цвет фона TextView в одной строке моего списка. Я понятия не имею, как я могу достичь определенной строки.Как достичь одной строки с помощью ListAdapter?

Мой XML:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LL_NoteRows" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/LL_NoteRow" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/text1" 
      android:layout_width="match_parent" 
      android:layout_height="35dp" 
      android:text="Tytuł" 
      android:textSize="25dp" /> 

     <TextView 
      android:id="@+id/text3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:maxLines="3" 
      android:text="Treść" 
      android:textColor="#505050" 
      android:textSize="15dp" /> 

     <TextView 
      android:id="@+id/NoteRowColor" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="TextView" /> 

    </LinearLayout> 

</LinearLayout> 

И функция, заполнить данные:

public void fillData() 
    { 
     Cursor notesCursor = mDbHelper.fetchAllNotes(); 
     startManagingCursor(notesCursor); 

     // Create an array to specify the fields we want to display in the list (only TITLE) 
     String[] from = new String[]{NotesDbAdapter.KEY_TITLE, NotesDbAdapter.KEY_BODY, NotesDbAdapter.KEY_COLOR}; 

     // and an array of the fields we want to bind those fields to (in this case just text1) 
     int[] to = new int[]{R.id.text1, R.id.text3, R.id.NoteRowColor}; 

     // Now create a simple cursor adapter and set it to display 
     SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to); 
     setListAdapter(notes); 
    } 

он работает отлично, но когда я пытаюсь сделать некоторые, как это:

LinearLayout rl=(LinearLayout)findViewById(R.id.LL_NoteRow); 

mColorText = (TextView) findViewById(R.id.NoteRowColor); 
String newColor = mColorText.getText().toString(); 

if(colorToSet.equals("blady_morski")) 
    rl.setBackgroundColor(getResources().getColor(R.color.blady_morski)); 

App аварии ,

+0

где он падает? –

+0

заменить mColorText = (TextView) findViewById (R.id.NoteRowColor); по mColorText = (TextView) rl.findViewById (R.id.NoteRowColor); –

+0

Привет, Что такое valure blady_morski в вашем цвете xml? – Jarvis

ответ

0

Вам потребуется подкласс SimpleCursorAdapter и переопределить getView(). Этот метод вызывается для каждой строки в списке, и вы можете выполнять свои настройки там.

Смежные вопросы