在listView中显示textView

Display textView in listView

如何显示Total旁边的total amount

代码段

        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();
            }
         }

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

How to display the total amount beside Total ?

因为totalTextViewfooter里面所以,按:

1. 在 class 级别而不是在任何方法内部声明 footer 并在添加到 ListView 页脚之前对其进行初始化:

...
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);