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

解决方案 »

  1.   


    适配器的问题? 在其他地方都可以显示的 用 SimpleCursorAdapter?  
      

  2.   

    这个地方改一下了 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});
    改成SimpleCursorAdapter adapter = new SimpleCursorAdapter(CheakOutActivity.this, R.layout.my_listitemcogoods, cursor1,new String[]{"category","fenliang","price"}, new int[]{R.id.Goodsname,R.id.Goodsfl,R.id.Goodsprice});  我的my_listitemcogoods的代码:<?xml version="1.0" encoding="utf-8"?>  
        <LinearLayout   
                android:layout_width="fill_parent"   
                xmlns:android="http://schemas.android.com/apk/res/android"   
                android:orientation="vertical"  
                android:layout_height="wrap_content"   
               
                android:paddingBottom="3dip"   
                android:paddingLeft="10dip">  
                <TextView   
                        android:layout_height="fill_parent"   
                        android:layout_width="fill_parent"   
                        android:id="@+id/Goodsname"   
                        android:textSize="30dip">  
                </TextView>  
                  
                <LinearLayout
                      android:layout_width="wrap_content"   
                      android:layout_height="wrap_content"   
                      android:orientation="horizontal"  
                      android:paddingBottom="3dip" 
                      android:layout_gravity="center|center_horizontal|center_vertical" 
                    >
                    <TextView 
                    android:id="@+id/Goodsfl"   
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           
            
            /> 
            <TextView 
                    android:id="@+id/Goodsprice"   
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
          
            android:layout_marginLeft="30dp"
            />         
                </LinearLayout>    
               
    </LinearLayout>  
      

  3.   

    你的代码有点意思,请问组件lvgoods有被显示到吗?
      

  4.   

    提示这个错误了
    Unable to start activity ComponentInfo{com.allen.jxc/com.allen.jxc.CheakOutActivity}: java.lang.ClassCastException: android.widget.ListView cannot be cast to android.widget.LinearLayout
      

  5.   

    那是布局的问题吗?
    我的界面布局代码:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
          android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="3dip"
        android:layout_weight="1"
        android:layout_gravity="center|center_horizontal|center_vertical"
       >
         <LinearLayout 
             android:orientation="vertical"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:layout_weight="1"
            android:background="@drawable/border"
             >
              
           <TextView
            
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
              android:id="@+id/tvorderno"
              android:text="单号:"
            />
             
        
                
         
            <ListView android:id="@+id/syListView" 
                android:layout_weight="1"
                android:layout_height="wrap_content" 
                
              android:layout_width="wrap_content">
                
            </ListView>  
         
         
           <LinearLayout 
            android:orientation="horizontal"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
            >
            
             <TextView
              
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
              android:id="@+id/tvtotal"
              android:text="总份数:10"
            />
              <TextView
            
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
              android:id="@+id/tvtotalprice"
              android:text="总金额:10"
            />
             
        </LinearLayout>
        
        <LinearLayout 
             android:orientation="horizontal"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
            >
            <Button 
                 android:id="@+id/btcoadd"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="添加"
                />
            
             <Button 
                 android:id="@+id/btcofj"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="附加"
                />
             
              
               
                 <Button 
                 android:id="@+id/btcojs"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="结算"
                />
            
        </LinearLayout>
             
         </LinearLayout>
         
         
         
         <LinearLayout 
             android:orientation="vertical"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_weight="1"
             >
         <LinearLayout 
             android:orientation="horizontal"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:id="@+id/llclass"
             >
         
         </LinearLayout>
         <ListView android:layout_width="fill_parent" 
                   android:layout_weight="2"  
                          android:layout_height="wrap_content"   
                          android:id="@+id/GoodsListView">  
                </ListView>  
                
         <ListView android:layout_width="wrap_content"
                   android:layout_weight="4"   
                          android:layout_height="wrap_content"   
                          android:id="@+id/sxListView">  
                </ListView>  
             
          <Button 
              android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="添加"
             />
         </LinearLayout>
        
      
         
         
        
    </LinearLayout>
      

  6.   

    lvgoods=(ListView) findViewById(R.id.GoodsListView);  
    代码放到
    DatabaseHelper dbhelper=new DatabaseHelper(CheakOutActivity.this,"jxc");
    上面试试看。
    adapter.notifySateChange...放在setAdapter方法后面调用
      

  7.   

    貌似你需要在最外层设置original=“vertical”  还有你的weight属性有什么用