Java 文本字段将不会填充

Java 文本字段将不会填充,java,android,textfield,Java,Android,Textfield,我为一个练习编写了一个小的android应用程序,但当我使用完EditText字段后,其他文本字段不会填充。找不到问题 package com.zschiff.invoice; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.widget.EditText; import android.widget.TextView; import andro

我为一个练习编写了一个小的android应用程序,但当我使用完EditText字段后,其他文本字段不会填充。找不到问题

package com.zschiff.invoice;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import java.text.NumberFormat;

public class invoice_total_activity extends Activity
implements OnEditorActionListener {
   // define the private widget variables
   private EditText subtotalEditText;
   private TextView discountPercentText;
   private TextView discountTextView;
   private TextView totalTextView;

  //define the instance variables
  private String subtotalString;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_invoice_total_activity);

     //create link to layout
     subtotalEditText = (EditText) findViewById(R.id.subtotalAmountEditText);
     discountPercentText = (TextView) findViewById(R.id.discountPercent);
     discountTextView = (TextView) findViewById(R.id.discountAmount);
     totalTextView = (TextView) findViewById(R.id.totalAmount);

     //set the listeners
     subtotalEditText.setOnEditorActionListener(this);
    }

    public void calculateAndDisplay() {

     //get the subtotal
     subtotalString = subtotalEditText.getText().toString();
     float subtotal;

     if (subtotalString.equals("")) {
         subtotal = 0;
     }
     else {
         subtotal = Float.parseFloat(subtotalString);
     }

     // get discount percent
     float discountPercent;
     if (subtotal >= 200) {
         discountPercent = .2f;
     }
     else if (subtotal >= 100) {
         discountPercent = .1f;
     }

     else {
         discountPercent = 0;
     }


     //calculate discount
     float discountAmount = subtotal * discountPercent;
     float total = subtotal - discountAmount;

     //display results
     NumberFormat percent = NumberFormat.getPercentInstance();
     discountPercentText.setText(percent.format(discountPercent));

     NumberFormat currency = NumberFormat.getCurrencyInstance();
     discountTextView.setText(currency.format(discountAmount));
     totalTextView.setText(currency.format(total));
   }

  @Override
  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

      calculateAndDisplay();

      return false;
   }
}
以下是android布局xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.zschiff.invoice.invoice_total_activity">

 <!-- Subtotal -->

 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/subtotal_label"
     android:id="@+id/subtotalLabel"
     android:textSize="20sp"
     android:textStyle="bold"
     android:layout_alignParentTop="true"
     android:layout_alignParentLeft="true"
     android:layout_alignParentStart="true"
     android:paddingTop="20dp" />

 <EditText
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:inputType="number"
     android:ems="7"
     android:id="@+id/subtotalAmountEditText"
     android:text="@string/subtotal_amount"
     android:textSize="20sp"
     android:layout_alignBottom="@id/subtotalLabel"
     android:layout_alignParentTop="true"
     android:layout_toRightOf="@+id/subtotalLabel"
     android:layout_toEndOf="@+id/subtotalLabel"
     android:layout_marginLeft="100dp" />

 <!-- Discount Percent -->

 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/discountPercentLabel"
     android:text="@string/discount_label"
     android:textSize="20sp"
     android:textStyle="bold"
     android:layout_below="@+id/subtotalLabel"
     android:layout_alignParentLeft="true"
     android:layout_alignParentStart="true"
     android:paddingTop="20dp"/>

 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/discountPercent"
     android:text="@string/discount_percent"
     android:textSize="20sp"
     android:layout_toRightOf="@+id/discountPercentLabel"
     android:layout_alignBottom="@+id/discountPercentLabel"
     android:layout_alignLeft="@+id/subtotalAmountEditText"
     android:layout_alignStart="@+id/subtotalAmountEditText" />

 <!-- Discount Amount -->

 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/discountAmountLabel"
     android:text="@string/discount_amount_label"
     android:textSize="20sp"
     android:textStyle="bold"
     android:layout_below="@+id/discountPercentLabel"
     android:layout_alignParentLeft="true"
     android:layout_alignParentStart="true"
     android:paddingTop="20dp" />

 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/discountAmount"
     android:text="@string/discount_amount"
     android:textSize="20sp"
     android:layout_toRightOf="@id/discountAmountLabel"
     android:layout_alignBottom="@+id/discountAmountLabel"
     android:layout_alignLeft="@+id/discountPercent"
     android:layout_alignStart="@+id/discountPercent" />

 <!-- Total Amount -->

 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/totalLabel"
     android:text="@string/total_label"
     android:textSize="20sp"
     android:textStyle="bold"
     android:layout_below="@+id/discountAmountLabel"
     android:layout_alignParentLeft="true"
     android:layout_alignParentStart="true"
     android:paddingTop="20dp" />

 <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:id="@+id/totalAmount"
     android:text="@string/total_amount"
     android:textSize="20sp"
     android:layout_toRightOf="@id/totalLabel"
     android:layout_alignBottom="@+id/totalLabel"
     android:layout_alignLeft="@+id/discountAmount"
     android:layout_alignStart="@+id/discountAmount" />
</RelativeLayout>

该应用程序运行,并接受编辑文本,但在此之后,什么也不会发生。非常感谢任何帮助

在EditText字段中输入一些数字后,按Enter键(如果正在运行模拟器)。我输入了一个数字,按enter键,得到了以下信息。。。

在EditText字段中输入一些数字后,按Enter键(如果您正在运行模拟器)。我输入了一个数字,按enter键,得到了以下信息。。。
谢谢大家的回答!AVD有点问题。我擦去了用户信息,它工作起来很有魅力。

谢谢大家的回答!AVD有点问题。我擦去了用户信息,它的工作就像一个符咒。

在xml格式的EditText上设置你的
imeOptions=“done”
,然后查看这个设置你的监听器同样尝试了这个问题设置你的
imeOptions=“done”
在xml格式的EditText上,然后查看此设置您的Listener尝试了同样的issueTried和still nothingTried和still nothing