关于ListView 显示的有关问题 !
关于ListView 显示的问题 在线等!!!!!
首先上我的代码:
Button 都可以正常显示 点击button 的时候Toast.makeText(CheakOutActivity.this, "父类ID:"+pid+"--"+cursor1.getCount(), 500).show(); 这一行也可以打印出来 而且cursor1.getCount()是大于0的 代表有查询到数据 但listview lvgoods 里面没有显示任何数据 也没有报错 郁闷 不知道从那有问题 请大侠们指教 一下 谢谢!
首先上我的代码:
LinearLayout layout;
layout=(LinearLayout)findViewById(R.id.llclass);
layout.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
DatabaseHelper dbhelper=new DatabaseHelper(CheakOutActivity.this,"jxc");
SQLiteDatabase db=dbhelper.getReadableDatabase();
Cursor cursor=db.query("pcategory", null, null, null, null, null, null);
if(cursor.getCount()>0)
{
Button Btn[] = new Button[cursor.getCount()];
int i=0;
while(cursor.moveToNext())
{
final String pid=cursor.getString(cursor.getColumnIndex("_id"));
String classname=cursor.getString(cursor.getColumnIndex("category"));
Btn[i]=new Button(this);
Btn[i].setId(2000+i);
Btn[i].setText(classname);
Btn[i].setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
lvgoods=(ListView) findViewById(R.id.GoodsListView);
DatabaseHelper dbhelper1=new DatabaseHelper(CheakOutActivity.this,"jxc");
SQLiteDatabase db1=dbhelper1.getReadableDatabase();
Cursor cursor1=db1.query("category", null, "pid='"+pid+"'", null, null, null, null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(CheakOutActivity.this, R.layout.my_listitemcoclass, cursor1,new String[]{"category","fenliang","price"}, new int[]{R.id.Goodsname,R.id.Goodsfl,R.id.Goodsprice});
lvgoods.setAdapter(adapter);
Toast.makeText(CheakOutActivity.this, "父类ID:"+pid+"--"+cursor1.getCount(), 500).show();
db1.close();
lvgoods.setOnItemClickListener(new ItemClickListener());
}
});
layout.addView(Btn[i],lp);
Button 都可以正常显示 点击button 的时候Toast.makeText(CheakOutActivity.this, "父类ID:"+pid+"--"+cursor1.getCount(), 500).show(); 这一行也可以打印出来 而且cursor1.getCount()是大于0的 代表有查询到数据 但listview lvgoods 里面没有显示任何数据 也没有报错 郁闷 不知道从那有问题 请大侠们指教 一下 谢谢!
- 1FBReaderJ学习笔记(3):Footer底部状态栏更改
- 2android 语言定做
- 3Android快速开发必不可少的11个工具类
- 4eclipse中怎么修改项目名称 具体操作
- 5Android学习笔记19:含有通知栏的进度条的Android下载文件
- 6Android带明白按钮的EditText
- 7android GPS 获取定位坐标信息解决方法
- 8ScrollView里嵌套ListView,怎么禁用ListView的滚动事件,或者触发ListView滚动时调用父元素ScrollView的滚动事件
- 9listview 动态添加,该如何解决
- 10(原)Android理论梳理-No1异步处理之Handler相干机制