2014-12-25 3 views
0

사용자 정의 레이아웃으로 ListView를 만들려고했지만 지금까지 성공적으로 할 수 없었습니다. 나는 초보자이며 튜토리얼을 따라 해냈다. 내가 응용 프로그램을 시작하면ListView with Custom Adaptor [안드로이드]

//this is where I want the custom list items to be displayed. 
    //GroupAdapter is the constructor of the class in which I'm trying to make a custom adapter 
    stringArray = new String[10]; 
    groupItemArrayAdapter = new GroupAdapter(this,stringArray); 
    groupListView = (ListView) findViewById(R.id.mainList); 
    groupListView.setAdapter(groupItemArrayAdapter); 

    //this is the code in GroupAdapter.java class 
    public class GroupAdapter extends ArrayAdapter{ 
    private LayoutInflater inflater; 

    public GroupAdapter(Activity activity, String[] items){ 
     super(activity,R.layout.group_view); 
     inflater=activity.getWindow().getLayoutInflater(); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent){ 
     return inflater.inflate(R.layout.group_view,parent,false); 
    } 
    } 

이 빈 화면이 나타납니다 이 내가 뭘하는지입니다. 처음에는 목록에 Android 기본 레이아웃을 사용했을 때 목록 항목이 표시되었지만 더 이상 표시되지 않았습니다 ... 내가 잘못하고있는 것을 이해하지 못합니다. 누구든지 도와 줄 수 있습니까? 여기

당신은 모든 코드를 대체 할 수 group_view.xml 파일

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

<TextView 
    android:id="@+id/gName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Group Name" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_marginRight="100dp" 
    android:textStyle="bold" /> 

<TextView 
    android:id="@+id/activity" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@color/signIn" 
    android:paddingLeft="15dp" 
    android:paddingRight="15dp" 
    android:text="5" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:textStyle="bold" /> 

</LinearLayout> 
+0

참조 http://www.vogella.com/tutorials/AndroidListView/article.html – gio

+0

@ (버전 가장 간단한) 것 지오 이미 도움이 안된다 – leMS

+0

@leMS는 레이아웃'layout.group_view'를 제공합니다 – gio

답변

0

당신이 원하는 경우, gName 필드에 문자열을 표시 할 때 경우에의
stringArray = new String[10]; 
groupItemArrayAdapter = new GroupAdapter(this,stringArray); 
groupListView = (ListView) findViewById(R.id.mainList); 
groupListView.setAdapter(new ArrayAdapter<String>(this, R.layout.group_view, R.id.gName, stringArray)); 

activity에서 촬영 한 다음 사용해야합니다.

답변 어째서 비어있는거야? "

@Override 
public View getView(int position, View convertView, ViewGroup parent){ 
    return inflater.inflate(R.layout.group_view,parent,false); 
} 

빈보기 만 팽창시키고 필드에 문자열을 할당하지 않습니다. 그것은

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    convertView = inflater.inflate(R.layout.group_view, parent, false); 
    TextView textView = (TextView)convertView.findViewById(R.id.gName); 
    String item = getItem(position) 
    textView.setText(item); 
    return convertView; 
} 
당신은 더 나은 버전을 읽어 본 후 글을 구현할 수 있습니다

Making ListView Scrolling Smooth