【Android studio】 【将Sqlite显示到listview】为什么我的listview只显示一个 item,数据库里明明有三四条数据
lv.setAdapter(new BaseAdapter() {
/*
为ListView设置一个适配器
getCount()返回数据个数
getView()为每一行设置一个条目
*/
@Override
public int getCount() {
return goodsArray.size();
}
@Override
public Object getItem(int position) {
// return studentlist.get(position);
return null;
}
@Override
public long getItemId(int position) {
// return position;
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view ;
/**对ListView的优化,convertView为空时,创建一个新视图;
convertView不为空时,代表它是滚出,
放入Recycler中的视图,若需要用到其他layout,
则用inflate(),同一视图,用fiindViewBy()
**/
if(convertView == null )
{
LayoutInflater inflater = getActivity().getLayoutInflater();
view = inflater.inflate(R.layout.item,null);
// view = inflater.inflate(R.layout.item,null);
//view = View.inflate(getBaseContext(),R.layout.item,null);
}
else
{
view = convertView;
}
//从goodsArray中取出一行数据,position相当于数组下标,可以实现逐行取数据
goodsInfo goodsinfo = goodsArray.get(position);
TextView name = (TextView)view.findViewById(R.id.listview_name);
TextView goods_number = (TextView)view.findViewById(R.id.listview_goodsnumber);
TextView in_price = (TextView)view.findViewById(R.id.listview_inprice);
TextView out_price = (TextView)view.findViewById(R.id.listview_outprice);
TextView update_time = (TextView)view.findViewById(R.id.listview_updatetime);
name.setText(goodsinfo.getName());
goods_number.setText(goodsinfo.getgoods_number());
in_price.setText(String.valueOf(goodsinfo.getin_price()));
out_price.setText(String.valueOf(goodsinfo.getout_price()));
update_time.setText(goodsinfo.getupdate_time());
return view;
}
});