在listView中显示textView

时间:2015-11-19 16:59:36

标签: android android-listview textview

如何在total amount旁边显示Total

enter image description here

代码段

        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>

1 个答案:

答案 0 :(得分:0)

  

如何显示总计旁边的总金额?

因为total TextView位于footer内,所以请执行以下操作:

1。在类级别而不是在任何方法内部声明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);