2013-05-15 1 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)); 

응용 프로그램 충돌 .

+0

어디에서 충돌이 발생합니까? –

+0

바꾸기 mColorText = (TextView) findViewById (R.id.NoteRowColor); 에 의해 mColorText = (TextView) rl.findViewById (R.id.NoteRowColor); –

+0

안녕하세요, xml 색상의 blady_morski의 valur가 무엇입니까? – Jarvis

답변

0

SimpleCursorAdapter의 하위 클래스를 지정하고 getView()을 재정의해야합니다. 이 메서드는 목록의 각 행에 대해 호출되며 사용자 정의 할 수 있습니다.

관련 문제