0
我想用自定義佈局構建一個ListView,但到目前爲止還沒有能夠成功地做到這一點。我是一名初學者,並且一直在跟隨教程來完成它。 這是我在做什麼:ListView與自定義適配器[Android]
//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>
看到http://www.vogella.com/tutorials/AndroidListView/article.html – gio
@ gio已經做了,沒有幫助 – leMS
@leMS提供xml佈局'layout.group_view' – gio