请帮助我如何通过编程来实现这样的事情。
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>下面是我可以在其中向列表视图添加详细信息的代码
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();
}谢谢你们!!
发布于 2014-03-28 19:13:47
你可以通过设置两个列表视图的适配器来显示列表视图,但从用户的角度来看,在一个屏幕上显示两个列表视图并不是一个好主意,而是使用一个具有文本视图的双线性布局作为标题,只需将列表加载到布局中,然后用户单击该线性布局,然后卸载或删除另一个。
要将适配器设置为列表视图,只需使用:
ListView.setAdapter(adapter);根据需要通过扩展ArrayAdapter<Object>或SimpleArrayAdapter来创建适配器类。
https://stackoverflow.com/questions/22711090
复制相似问题