我在视图上得到一个空列表,没有任何错误,但在我的数组不为空时只得到 list empry。
我的xml是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLa"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainListView"/>
<ImageView
android:id="@+id/iconremove"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="centerCrop"
android:src="@drawable/removeicon"
android:visibility="gone"
/>
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="10dip"
android:layout_weight="1"
android:textSize="20dip" />
</LinearLayout>
我的适配器
public class ListRssAdpter extends ArrayAdapter {
private Context mContext;
private int id;
private List<String> items;
public ListRssAdpter(Context context, int textViewResourceId, List<String> list) {
super(context, textViewResourceId, list);
mContext = context;
id = textViewResourceId;
items = list;
}
@Override
public View getView(int position, View v, ViewGroup parent) {
View mView = v;
if (mView == null) {
LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = vi.inflate(id, null);
}
TextView tx = (TextView) mView.findViewById(R.id.textView);
//if this view is on main screen
if (tx == null) {
tx = ((TextView) mView);
}
tx.setText(items.get(position));
return mView;
}
}
和主要代码:
ListView lv = (ListView) findViewById(R.id.mainListView );
lv.setTextFilterEnabled(true);
DBAdapter dbAdpter=new DBAdapter(this);
ListRssLinkAndTitle=(ArrayList)dbAdpter.getWantedItemsList(this,"link","RssTitle","Rtl");//get wanted items from db
ArrayList<String> listKeys=new ArrayList<String>();
for (int j=0;j<ListRssLinkAndTitle.size();j++)
listKeys.add(ListRssLinkAndTitle.get(j).title);
ListRssAdpter listAdapter = new ListRssAdpter(this, R.layout.titlesrss, listKeys);
if (ListRssLinkAndTitle.isEmpty())
Toast.makeText(this.getApplicationContext(), getResources().getString(R.string.emtyRssList),0).show();
lv.setAdapter(listAdapter);
帮助的坦克