2017-05-05 1 views
0

SimpleCursorAdapter로 채워진 ListView가 있습니다. listview는 데이터베이스의 한 컬럼에 대한 내용을 보여줍니다. 이 칼럼은 내가 영어로 작성한 수업 (예 : 수학)에서 나온 것입니다. 나는 (Reading Writting .. 같은) 각 공과마다 주제를 가지고있다. 그리고 그것도 같은 테이블의 칼럼입니다. 내 listView에서는 "English"만 표시되지만 "English - Reading"을 보여주고 싶습니다. 그래서 차이를 만들 수 있습니다.SimpleCursorAdapter를 사용하여 listView에 둘 이상의 열을 표시합니다.

어떻게하면됩니까?

btw, 강의에 대한 내 열은 'branche_cours'이고 표시하려는 다른 열은 '지정'입니다.

여기 당신의 행 항목에 대한 레이아웃 list_item.xml 만들기 내 SimpleCursorAdapter

 lvCours =(ListView)findViewById(R.id.ListCours); 
    final Cursor cursor = dbhelper.getAllCours(); 
    String[] from = { "branche_cours" }; int[] to = { android.R.id.text1 }; 
    adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor, from, to, 0); 
    lvCours.setAdapter(adapter); 
    adapter.notifyDataSetChanged(); 
+0

나는 아직 해결책 foundthe하지 않은 사람 .. – Dom

답변

0

1.입니다. 당신의 Activity에서

enter image description here

2 텍스트 뷰 R.id.text_designation에 텍스트 뷰 R.id.text_branche_coursbranche_coursdesignation을 표시하려면 다음을 수행

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="16dp"> 

    <TextView 
     android:id="@+id/text_branche_cours" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@android:color/black" 
     android:text="English"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@android:color/black" 
     android:text=" - " /> 

    <TextView 
     android:id="@+id/text_designation" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@android:color/black" 
     android:text="Reading" /> 
</LinearLayout> 

: 여기

lvCours = (ListView)findViewById(R.id.ListCours); 
final Cursor cursor = dbhelper.getAllCours(); 

String[] from = { "branche_cours", "designation" }; 
int[] to = { R.id.text_branche_cours, R.id.text_designation }; 

adapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor, from, to, 0); 
lvCours.setAdapter(adapter); 
adapter.notifyDataSetChanged(); 

는 좋은 Tutorial입니다.

희망이 도움이됩니다 ~

+0

아주 좋은 답변! 고맙습니다 ! 완벽하게 작동했습니다! – Dom

+0

도와 드리겠습니다 :) – FAT

관련 문제