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