2013-10-30 24 views
1

我要對齊我在同一行的TextView和微調像this image但我的屏幕看起來像this對齊的TextView和微調在同一行

此外,我怎麼能與微調的值更新價格TextView的?假設產品價格是200美元,當我選擇微調控件textview更改爲400美元時。我怎麼做?

<LinearLayout 
    android:layout_width="fill_parent" 
    android:orientation="vertical" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:background="#E5E5E5" 
    android:layout_height="fill_parent"> 

    <TextView 
     android:id="@+id/TextViewTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:text="Qty" 
     android:textSize="10pt"></TextView> 

    <Spinner 
     android:id="@+id/SpinnerFeedbackType" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:layout_width="fill_parent" 
     android:entries="@array/feedbacktypelist"></Spinner> 

    <EditText 
     android:id="@+id/EditTextName" 
     android:layout_height="wrap_content" 
     android:hint="Name" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:inputType="textPersonName" 
     android:layout_width="fill_parent"></EditText> 

    <EditText 
     android:id="@+id/EditTextEmail" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:hint="Email" 
     android:inputType="textEmailAddress" 
     android:layout_width="fill_parent"></EditText> 
    <EditText 
     android:id="@+id/EditTextMobile" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:hint="Mobile Number" 
     android:inputType="textEmailAddress" 
     android:layout_width="fill_parent"></EditText> 
     <EditText 
     android:id="@+id/EditCity" 
     android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:hint="City" 
     android:inputType="textEmailAddress" 
     android:layout_width="fill_parent"></EditText> 


    <EditText 
     android:id="@+id/EditTextFeedbackBody" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:hint="Address" 
     android:inputType="textMultiLine" 
     android:lines="5" 
     android:layout_width="fill_parent"></EditText> 


    <EditText 
     android:id="@+id/EditTextComments" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:hint="Comments" 
     android:inputType="textMultiLine" 
     android:lines="5" 
     android:layout_width="fill_parent"></EditText> 


    <TextView 
     android:id="@+id/TextViewTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:text="Total Order Price:" 
     android:textSize="10pt"></TextView> 



    <TextView 
     android:id="@+id/TextViewTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:text="Rs.6,849" 
     android:textSize="10pt"></TextView> 





    <CheckBox 
     android:id="@+id/CheckBoxResponse" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:text="@string/feedbackresponse" 
     android:layout_width="fill_parent"></CheckBox> 

    <Button 
     android:id="@+id/ButtonSendFeedback" 
     android:layout_height="wrap_content" 
     android:padding="5dp" 
     android:text="@string/feedbackbutton" 
     android:onClick="sendFeedback" 
     android:layout_width="fill_parent"></Button> 

    </LinearLayout> 

回答

0

在水平線性佈局中放置微調器和文本視圖。

實現spinner.setOnItemSelectedListener(AdapterView.OnItemSelectedListener)。並根據需要更改TextView文本。

spinner.setOnItemSelectedListener(new OnItemSelectedListener() 
{ 

    public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) 

    {   
       String txtNo=textView.getText().toString().replaceAll("[^0-9]", ""); 
       textView.setText(Integer.parseInt(Spinner.getSelectedItem().toString())* 
       Integer.parseInt(txtNo)); 
    } 

    });  
+0

telll me full senario whe spinner sleect它的數量如何倍增價格? – user2931692

+0

請查看更新後的答案。 –

+0

顯示錯誤java.lang.NumberFormatException:無法解析'Rs.6,849'爲整數 – user2931692

2

這是因爲你使用的方向爲垂直於父layout.And你沒有給任何parentLayout的設置要顯示水平的意見。 將兩個TextView的和微調在LinearLayout中與定向水平

嘗試下面的數據:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:orientation="horizontal" 
    android:layout_height="fill_parent"> 
<TextView 
     android:id="@+id/TextViewTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:text="Qty" 
     android:textSize="10pt"></TextView> 

    <Spinner 
     android:id="@+id/SpinnerFeedbackType" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_width="wrap_content" 
     android:weight=".5" 
     android:entries="@array/feedbacktypelist"></Spinner> 
</LinearLayout> 

不要計算你setOnItemSelectedListener

priceTextView.setText(Integer.parseInt(Spinner.getSelectedItem().toString())* 
       Integer.parseInt(productPrice)); 

考慮您的productPrice的字符串

+0

,但我想顯示我attect上述 – user2931692

+0

如何更新價格whren選擇任意數量的形式微調同一樣的圖像???? – user2931692

+0

上面的數據會給你想要的圖像佈局 – Manishika

0

總結他們爲水平方向,這樣的線性佈局...

<LinearLayout 
    android:id="@+id/dd" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 
    <TextView 
     android:id="@+id/TextViewTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:text="Qty" 
     android:textSize="10pt" > 
    </TextView> 
    <Spinner 
     android:id="@+id/SpinnerFeedbackType" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" > 
    </Spinner> 
</LinearLayout> 
0

內,您的當前的垂直佈局,包裹TextView的微調,並與具有水平方向的LinearLayout中。

至於第二個問題,您只需將價格乘以您的數量字段中的數字(可從mySpinner.getSelectedItem()獲得並根據需要進行轉換)。

1

使XML這樣的,這將解決您的問題

<LinearLayout 
    android:layout_width="fill_parent" 
    android:orientation="vertical" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:background="#E5E5E5" 
    android:layout_height="fill_parent"> 

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" 

> 

    <TextView 
     android:id="@+id/TextViewTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:text="Qty" 
     android:textSize="10pt"></TextView> 

    <Spinner 
     android:id="@+id/SpinnerFeedbackType" 
     android:layout_height="wrap_content" 

      android:layout_marginRight="10dp" 
     android:layout_width="40dp" 
     android:entries="@array/feedbacktypelist"></Spinner> 

</LinearLayout> 

    <EditText 
     android:id="@+id/EditTextName" 
     android:layout_height="wrap_content" 
     android:hint="Name" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:inputType="textPersonName" 
     android:layout_width="fill_parent"></EditText> 

    <EditText 
     android:id="@+id/EditTextEmail" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:hint="Email" 
     android:inputType="textEmailAddress" 
     android:layout_width="fill_parent"></EditText> 
    <EditText 
     android:id="@+id/EditTextMobile" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:hint="Mobile Number" 
     android:inputType="textEmailAddress" 
     android:layout_width="fill_parent"></EditText> 
     <EditText 
     android:id="@+id/EditCity" 
     android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:hint="City" 
     android:inputType="textEmailAddress" 
     android:layout_width="fill_parent"></EditText> 


    <EditText 
     android:id="@+id/EditTextFeedbackBody" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:hint="Address" 
     android:inputType="textMultiLine" 
     android:lines="5" 
     android:layout_width="fill_parent"></EditText> 


    <EditText 
     android:id="@+id/EditTextComments" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:hint="Comments" 
     android:inputType="textMultiLine" 
     android:lines="5" 
     android:layout_width="fill_parent"></EditText> 


    <TextView 
     android:id="@+id/TextViewTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:text="Total Order Price:" 
     android:textSize="10pt"></TextView> 



    <TextView 
     android:id="@+id/TextViewTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:text="Rs.6,849" 
     android:textSize="10pt"></TextView> 





    <CheckBox 
     android:id="@+id/CheckBoxResponse" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
     android:text="@string/feedbackresponse" 
     android:layout_width="fill_parent"></CheckBox> 

    <Button 
     android:id="@+id/ButtonSendFeedback" 
     android:layout_height="wrap_content" 
     android:padding="5dp" 
     android:text="@string/feedbackbutton" 
     android:onClick="sendFeedback" 
     android:layout_width="fill_parent"></Button> 

    </LinearLayout>