Android 在listView中显示textView
如何在Android 在listView中显示textView,android,android-listview,textview,Android,Android Listview,Textview,如何在总计旁边显示总计 代码片段 View claims = inflater.inflate(R.layout.receipt_text, container, false); v=(ImageView)claims.findViewById(R.id.imageView4); listV = (ListView) claims.findViewById(R.id.listView1); UnderListViewButton=
总计
旁边显示总计
代码片段
View claims = inflater.inflate(R.layout.receipt_text, container, false);
v=(ImageView)claims.findViewById(R.id.imageView4);
listV = (ListView) claims.findViewById(R.id.listView1);
UnderListViewButton=(Button)claims.findViewById(R.id.btnSave); // save button below listView
FrameLayout footerLayout = (FrameLayout)getActivity().getLayoutInflater().inflate(R.layout.under_listview_button,null);
UnderListViewButton = (Button) footerLayout.findViewById(R.id.btnSave);
ViewGroup footer = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.total,null);
listV.addFooterView(footer);
listV.addFooterView(footerLayout);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 0:
result = data.getStringExtra("text"); //67
name = data.getStringExtra("a"); //Project
description = data.getStringExtra("c");
as = as + Long.parseLong(result);
Log.d("FIRST", "result:" + result);
Text = " " + name + " " + "RM" + result + "";
if (mClickedPosition == -1) {
m_listItems.add(Text);
m_listBitmapItems.add(Global.img);
} else {
m_listItems.set(mClickedPosition, Text);
m_listBitmapItems.set(mClickedPosition, Global.img);
}
adapter.notifyDataSetChanged();
listV.setAdapter(adapter);
break;
case 2: .......
.......
}
long samount=as+bs+cs+ds+es; // total get correctly
Toast.makeText(getActivity(),samount+"", Toast.LENGTH_LONG).show();
}
}
收据\u文本\u xml//用于主
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:padding="10dp"
android:text="@string/text" android:textSize="20sp" />
<ListView android:id="@+id/listView1" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
total.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="51dp"
android:text="Total"
android:textSize="25sp"
android:background="@drawable/border_text"
android:layout_x="10dp"
android:layout_y="-5dp">
</TextView>
</AbsoluteLayout>
如何在合计旁边显示合计金额
因为total
TextView
在footer
内,所以请按以下步骤操作:
1。在类级别而不是在任何方法中声明footer
,并在添加到ListView footer之前对其进行初始化:
...
footer = (AbsoluteLayout) getActivity().
getLayoutInflater().inflate(R.layout.total,null);
listV.addFooterView(footer);
...
2.在onActivityResult
中使用findViewById
使用footer
访问total
TextView
:
TextView totalTextView = (TextView)footer.findViewById(R.id.tv);
totalTextView.setText("Total :"+ samount);
为什么要结束我的问题?我是否需要在
total.xml
中再添加一个TextView
?@Tony:如果要在右对齐处显示总量,则添加它;如果要在左对齐处显示total
文本,则添加它如果我使用您的代码,则不需要右对齐?因为您使用了totalTextView.setText(“Total:+samount”)代码>它在我将totalTextView
设置为全局并移动totalTextView=(TextView)footer.findViewById(R.id.tv)后工作代码>到onCreateView
<代码>页脚
无法解析,如果我将其放在ActivityResult的中
谢谢。高度赞赏:)