我在我的 Fragment 和我自己的适配器中创建了一个 listView 来为 listView 创建我自己的布局,但它没有显示任何内容
我的 listView 布局的 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill|right" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/textView_listViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView_adressList1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bronze_pin_level" />
<ImageView
android:id="@+id/imageView_adressList2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bronze_pin_level" />
<ImageView
android:id="@+id/imageView_adressList3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bronze_pin_level" />
</LinearLayout>
</LinearLayout>
我的 listView 的 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="vertical" >
<ListView
android:id="@+id/listView_adressList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.25" >
</ListView>
<ImageView
android:id="@+id/imageView_adressList1"
android:layout_width="match_parent"
android:layout_height="43dp"
android:src="@drawable/bottom_me" />
片段代码:
public class FragList extends Fragment {
ListView listView;
View myFragmentView;
List<String> adressList;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
myFragmentView = inflater.inflate(R.layout.frag_list, container, false);
listView = (ListView) myFragmentView
.findViewById(R.id.listView_adressList);
adressList = new ArrayList<String>();
adressList.add("Marvin");
adressList.add("Markus");
adressList.add("Bob");
ArrayAdapter<String> adapter = new MyAdapter(getActivity(),
R.layout.adress_list_layout, adressList);
listView.setAdapter(adapter);
return myFragmentView;
}
public class MyAdapter extends ArrayAdapter<String>{
private List<String> values;
ImageView btn1, btn2, btn3;
Context cont;
int layoutID;
public MyAdapter(Context context, int resource, List<String> values) {
super(context, resource);
this.values = values;
this.cont = context;
this.layoutID = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.cont
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(this.layoutID,
parent, false);
TextView tv1 = (TextView) rowView
.findViewById(R.id.textView_listViewText);
tv1.setText(values.get(position));
btn1 = (ImageView) rowView
.findViewById(R.id.imageView_adressList1);
btn2 = (ImageView) rowView
.findViewById(R.id.imageView_adressList2);
btn3 = (ImageView) rowView
.findViewById(R.id.imageView_adressList3);
return rowView;
}
}
}
问题是 listView 未显示在屏幕上。这只是一个白屏。显然我做错了什么,但我不知道是什么。