2014-03-28 107 views
0

请帮助我如何以编程方式实现此类功能。如何在textview-listview-textview之后放置textview-listview-textview android

的TextView
的ListView
的TextView

的TextView
的ListView
的TextView

这里是layout.xml

<LinearLayout 
    android:id="@+id/layoutlist" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/gsy" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/rsegtitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="RateSegmentname"/> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:layout_marginTop="10dp" > 

    </ListView> 

    <TextView 
     android:id="@+id/total" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Total"/> 

    </LinearLayout> 

下面是代码,其中i可以添加细节到listview

for(a = 1; a < ratesegcode; a++){ 

    ArrayList<ClassForComputation> listcomputation = new ArrayList<ClassForComputation>(); 

     double sum = 0; 
     double gamount = 0; 

     String query = "SELECT rcomponent, amnt, gamount FROM computation WHERE ratesegmentcode =\""+a+"\" ORDER BY ratesegmentcode, printorder"; 
     Cursor c = db.rawQuery(query, null); 

      if(c != null && c.getCount() != 0){ 
       c.moveToFirst(); 
      do{ 

       TextView rsegtitle = (TextView)findViewById(R.id.rsegtitle); 
       rsegtitle.setText(GetRateSegment(a));      
       ClassForComputation clsfrcomp = new ClassForComputation();   
       clsfrcomp.setratecomponent(c.getString(c.getColumnIndex("rcomponent")));    
       clsfrcomp.setamount(c.getDouble(c.getColumnIndex("amnt")));    
       gamount = c.getDouble(c.getColumnIndex("gamount"));    
       clsfrcomp.setgrossamount(gamount); 

       sum = sum + gamount; 

       listcomputation.add(clsfrcomp); 

      }while(c.moveToNext()); 

      PowerUtilityAdapter powerListAdapter = new PowerUtilityAdapter(this, listcomputation); 

      lv.setAdapter(powerListAdapter); 
      } 

      TextView total = (TextView)findViewById(R.id.total); 
      String totl = Double.toString(sum); 
      total.setText(totl); 

     c.close(); 
    } 

谢谢你们!

回答

0

您可以通过将适配器设置为列表视图来显示列表视图,但从用户的角度来看,屏幕上的两个列表视图不是一个好主意,而是使用两个具有textview的linearlayout一个标题,只需在用户点击线性布局时将列表加载到布局,然后卸载或去除其他布局。

要设置适配器列表视图只需使用:

ListView.setAdapter(adapter); 

创建一个适配器类由根据您的需要扩展ArrayAdapter<Object>SimpleArrayAdapter

相关问题