在对话框中显示多列Listview

时间:2014-03-29 04:02:59

标签: android listview

我正在尝试在对话框中加载多列列表视图。列表数据通过外部Web服务获取并存储在地图中,然后存储在Arralylist mlist中。该列表将填充数据。我试图在嵌入对话框的多列listview中显示这些数据。我试图在下面的代码

的帮助下做到这一点
Dialog dialog1;
                     new fetchData().execute("1");

                    View vls;
                    SimpleAdapter sa = new SimpleAdapter(context, mlist,
                            R.layout.custom,
                            new String[] { "Col1", "Col2","Col3" }, new int[] {
                                    R.id.C1, R.id.C2, R.id.C3 });
                    vls= MainActivity.this.getLayoutInflater().inflate(R.layout.custom,
                             null);
                     dialog1 = new Dialog(MainActivity.this);
                     dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);

                     ListView list =(ListView)vls.findViewById(R.id.ll1);
                        list.setAdapter(sa);
                         dialog1.setContentView(vls);


                     dialog1.show();

这是custom.xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
<ListView 
        android:id="@+id/ll1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

</ListView>
</LinearLayout>

下面是listview.xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
  android:paddingTop="4dip"
 android:paddingBottom="6dip"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal">

 <TextView
        android:id="@+id/C1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"        
        android:gravity="center"
        android:layout_weight="1"
        android:text="C1" />    
    <TextView
        android:id="@+id/C2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"        
        android:gravity="center"      
        android:layout_weight="1"  
        android:text="C2" />   
         <TextView
        android:id="@+id/C3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"        
        android:gravity="center"      
        android:layout_weight="1"  
        android:text="C3" />   
</LinearLayout>

代码运行时没有任何错误,但它不会在对话框中显示任何数据。请帮忙!

0 个答案:

没有答案