2015-11-19 3 views
-1

Как отобразить total amount у Total?Показать textView в listView

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

Почему хотел закрыть мой вопрос? – Tony

ответ

0

Как отобразить общую сумму около Total?

Поскольку totalTextView внутри footer так, сделайте это как:

1. Объявить footer на уровне класса, а не внутри любого метода и инициализировать его перед добавлением ListView сноске:

... 
footer = (AbsoluteLayout) getActivity(). 
     getLayoutInflater().inflate(R.layout.total,null); 
listV.addFooterView(footer); 
... 

2.onActivityResultfindViewById используя footer доступа totalTextView:

TextView totalTextView = (TextView)footer.findViewById(R.id.tv); 
totalTextView.setText("Total :"+ samount); 
+0

Нужно ли добавить еще один 'TextView' в' total.xml'? – Tony

+0

@Tony: Да, добавьте его, если хотите показать общую сумму при выравнивании по правому краю и 'Total' текст в левой стороне выравнивания –

+0

Если я использую ваш код, то не нужно? так как вы использовали 'totalTextView.setText (« Всего: »+ samount),' – Tony

Смежные вопросы