首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

关于ListView 显示的有关问题 !

2013-07-04 
关于ListView 显示的问题在线等!!!!!首先上我的代码: LinearLayout layout layout(LinearLayout)findVie

关于ListView 显示的问题 在线等!!!!!
首先上我的代码:


 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 里面没有显示任何数据  也没有报错  郁闷 不知道从那有问题 请大侠们指教  一下 谢谢!


[解决办法]
适配器的问题吧。要不自定义一个适配器?
[解决办法]
以你的描述,数据都查到了但是没有任何显示,我只能想到是适配器的问题。
难倒你的数据库里没有数据?
[解决办法]
你的代码有点意思,请问组件lvgoods有被显示到吗?
[解决办法]
lvgoods=(ListView) findViewById(R.id.GoodsListView);  
代码放到
DatabaseHelper dbhelper=new DatabaseHelper(CheakOutActivity.this,"jxc");
上面试试看。
adapter.notifySateChange...放在setAdapter方法后面调用
[解决办法]
貌似你需要在最外层设置original=“vertical”  还有你的weight属性有什么用

热点排行