首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在android中将textview-listview-textview放在textview-listview-textview之后

如何在android中将textview-listview-textview放在textview-listview-textview之后
EN

Stack Overflow用户
提问于 2014-03-28 19:05:42
回答 1查看 70关注 0票数 0

请帮助我如何通过编程来实现这样的事情。

TextView

ListView

TextView

TextView

ListView

TextView

这是layout.xml

代码语言:javascript
复制
 <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>

下面是我可以在其中向列表视图添加详细信息的代码

代码语言:javascript
复制
  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();  
    }

谢谢你们!!

EN

回答 1

Stack Overflow用户

发布于 2014-03-28 19:13:47

你可以通过设置两个列表视图的适配器来显示列表视图,但从用户的角度来看,在一个屏幕上显示两个列表视图并不是一个好主意,而是使用一个具有文本视图的双线性布局作为标题,只需将列表加载到布局中,然后用户单击该线性布局,然后卸载或删除另一个。

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

代码语言:javascript
复制
ListView.setAdapter(adapter);

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22711090

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档