我有一行的ListView(列表視圖是內部的LinearLayout)等ListView中沒有顯示結果,但是通過代碼
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<CheckBox
android:id="@+id/chk"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txtChoice"
android:textColor="#FF0000"
android:text="TEST"
android:layout_toRightOf="@id/chk"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
和適配器等內部類
private class SimpleAdapter extends BaseAdapter {
private String[] list=null;
public SimpleAdapter(String[] list) {
this.list = list;
}
@Override
public int getCount() {
return list.length;
}
@Override
public Object getItem(int position) {
return list[position];
}
@Override
public long getItemId(int position) {
return list[position].hashCode();
}
// Generate view for coupon's row
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if(view == null){
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.row, null);
}
return view;
}
}
和我設置適配器等
SimpleAdapter m=new SimpleAdapter(data);
listView.setAdapter(m);
data is String[] data=new String[]{"test","test_1"};
但列表不顯示任何事情。我流下了眼淚,它正常地流逝,但沒有任何表現。有什麼問題?
你在哪裏使用getView()中的列表對象? – Pratik