如何在android中的textview-listview-textview之后放置textview-listview-textview

时间:2014-03-28 11:05:42

标签: android listview android-listview

请帮助我如何以编程方式实现这样的功能。

的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>

以下是我可以向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();  
    }

谢谢你们!

1 个答案:

答案 0 :(得分:0)

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

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

ListView.setAdapter(adapter);

根据您的需要,通过扩展ArrayAdapter<Object>SimpleArrayAdapter创建适配器类。

相关问题