Java 三个变量之和(编辑文本),无需在第四个变量(文本视图)中打印按钮
我正在尝试制作一个计算平均值的应用程序,我有name、calif1、cal2、cal3、prom字段。 但是不必有任何按钮来帮助发送操作并返回prom中的内容,因此我想看看是否有可能添加calX的三个变量,而不需要按钮,并且该结果存储在变量prom中,因此在文本视图中打印之后(通过刷新或自动求和不断添加)。 注意:CALF1、cal2、cal3是编辑文本,prom是文本视图。 P.D:我看到了使用Action Go ime作为按钮的可能性,但我不知道这是否可行Java 三个变量之和(编辑文本),无需在第四个变量(文本视图)中打印按钮,java,android,text,Java,Android,Text,我正在尝试制作一个计算平均值的应用程序,我有name、calif1、cal2、cal3、prom字段。 但是不必有任何按钮来帮助发送操作并返回prom中的内容,因此我想看看是否有可能添加calX的三个变量,而不需要按钮,并且该结果存储在变量prom中,因此在文本视图中打印之后(通过刷新或自动求和不断添加)。 注意:CALF1、cal2、cal3是编辑文本,prom是文本视图。 P.D:我看到了使用Action Go ime作为按钮的可能性,但我不知道这是否可行 <TableRow
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/editText7"
android:layout_width="150dp"
android:layout_height="35dp"
android:ems="10"
android:inputType="textPersonName"
android:textSize="14sp" />
<EditText
android:id="@+id/editText8"
android:layout_width="35dp"
android:layout_height="35dp"
android:ems="10"
android:inputType="number"
android:textSize="14sp"
android:maxLength="2"
android:digits="1234567890"
android:singleLine="true"/>
<EditText
android:id="@+id/editText9"
android:layout_width="35dp"
android:layout_height="35dp"
android:ems="10"
android:inputType="number"
android:textSize="14sp"
android:maxLength="2"
android:digits="1234567890"
android:singleLine="true"/>
<EditText
android:id="@+id/editText10"
android:layout_width="35dp"
android:layout_height="35dp"
android:ems="10"
android:inputType="number"
android:textSize="14sp"
android:maxLength="2"
android:digits="1234567890"
android:singleLine="true"
android:imeOptions="actionGo"/>
<TextView
android:id="@+id/textView11"
android:layout_width="35dp"
android:layout_height="35dp"
android:ems="10"
android:text="TextView"
android:textSize="14sp"
android:maxLength="3"
android:singleLine="true"/>
</TableRow>
当editText字段上有值时,可以使用textChangedListener获取回调并计算平均值 参考:
使用android:imeoptions也可以获得类似的结果。您可以将textChangeListerner用于您拥有的三个EditText
calif1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
if (s.length() > 0) {
int a = Integer.parseInt(calif.getText().toString())+
Integer.parseInt(cal1.getText().toString()) +
Integer.parseInt(cal2.getText().toString())
prom.setText(""+a);
}
}
}
});
我想写一个方法,但我不知道编辑文本中输入的值是有序的还是随机的??