Android 如何使用TextWatcher计算值
我想计算我在计算方法中给出的T,T2,T3,T4的总和 如何使用TextWatcher计算此值 如果我在计算3的方法中不加任何值。如何在T3中存储0值 比如说Android 如何使用TextWatcher计算值,android,if-statement,textwatcher,Android,If Statement,Textwatcher,我想计算我在计算方法中给出的T,T2,T3,T4的总和 如何使用TextWatcher计算此值 如果我在计算3的方法中不加任何值。如何在T3中存储0值 比如说 T= 2*3*1/144*2 = 0.08333 T2=2*3*1/144*2 = 0.08333 T3= if no any num of value put =0 T4=2*3*1/144*2 = 0.08333 fullTotal = 0.2499 I want this type of output. please help m
T= 2*3*1/144*2 = 0.08333
T2=2*3*1/144*2 = 0.08333
T3= if no any num of value put =0
T4=2*3*1/144*2 = 0.08333
fullTotal = 0.2499
I want this type of output. please help me
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Edtinch1 = (EditText)findViewById(R.id.inch1);
Edtinch2 = (EditText)findViewById(R.id.inch2);
Edtfeet = (EditText)findViewById(R.id.feet);
Edtquan = (EditText)findViewById(R.id.qunt);
Totaltxt1= (EditText)findViewById(R.id.total1);
Edtquan.addTextChangedListener(this);
Edtinch21 = (EditText)findViewById(R.id.inch21);
Edtinch22 = (EditText)findViewById(R.id.inch22);
Edtfeet2 = (EditText)findViewById(R.id.feet2);
Edtquan2 = (EditText)findViewById(R.id.qunt2);
Totaltxt2= (EditText)findViewById(R.id.total2);
Edtquan2.addTextChangedListener(this);
Edtinch31 = (EditText)findViewById(R.id.inch31);
Edtinch32 = (EditText)findViewById(R.id.inch32);
Edtfeet3 = (EditText)findViewById(R.id.feet3);
Edtquan3 = (EditText)findViewById(R.id.qunt3);
Totaltxt3= (EditText)findViewById(R.id.total3);
Edtquan3.addTextChangedListener(this);
fulltotal1=(EditText)findViewById(R.id.fulltotal);
btnsnap = (Button)findViewById(R.id.btncapture);
btnsnap.setOnClickListener(this);
}
public void calculate(){
//get entered texts from the edittexts,and convert to integers.
inch11 = Double.parseDouble(Edtinch1.getText().toString());
inch12 = Double.parseDouble(Edtinch2.getText().toString());
feet11 = Double.parseDouble(Edtfeet.getText().toString());
quan11 = Double.parseDouble(Edtquan.getText().toString());
//do the calculation
Double calculated1 = (inch11*inch12)*(feet11)/144*(quan11);
//set the value to the textview, to display on screen.
T= calculated1.toString();
Totaltxt1.setText(T);
}
public void calculate2(){
//get entered texts from the edittexts,and convert to integers.
inch21 = Double.parseDouble(Edtinch21.getText().toString());
inch22 = Double.parseDouble(Edtinch22.getText().toString());
feet2 = Double.parseDouble(Edtfeet2.getText().toString());
quan2 = Double.parseDouble(Edtquan2.getText().toString());
//do the calculation
Double calculated2 = (inch21*inch22)*(feet2)/144*(quan2);
//set the value to the textview, to display on screen.
T2= calculated2.toString();
Totaltxt2.setText(T2);
}
public void calculate3(){
//get entered texts from the edittexts,and convert to integers.
inch31 = Double.parseDouble(Edtinch31.getText().toString());
inch32 = Double.parseDouble(Edtinch32.getText().toString());
feet3 = Double.parseDouble(Edtfeet3.getText().toString());
quan3 = Double.parseDouble(Edtquan3.getText().toString());
//do the calculation
Double calculated3 = (inch31*inch32)*(feet3)/144*(quan3);
//set the value to the textview, to display on screen.
T3= calculated3.toString();
Totaltxt3.setText(T3);
}
public void calculate4(){
//get entered texts from the edittexts,and convert to integers.
inch41 = Double.parseDouble(Edtinch41.getText().toString());
inch42 = Double.parseDouble(Edtinch42.getText().toString());
feet4 = Double.parseDouble(Edtfeet4.getText().toString());
quan4 = Double.parseDouble(Edtquan4.getText().toString());
//do the calculation
Double calculated4 = (inch41*inch42)*(feet4)/144*(quan4);
//set the value to the textview, to display on screen.
T4= calculated4.toString();
Totaltxt4.setText(T4);
}
public void fullcalculate()
{
}
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int arg1, int arg2,
int arg3) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
if (Edtinch1.getText().toString().length() <= 0)
{
Edtinch1.setError("Input Inch");
}
else if (Edtinch2.getText().toString().length() <= 0)
{
Edtinch2.setError("Input Inch");
}
else if (Edtfeet.getText().toString().length() <= 0)
{
Edtfeet.setError("Input feet");
}
else if (Edtquan.getText().toString().length() <= 0) {
Edtquan.setError("Input Quantity");
}
else
{
if (Edtquan.getText().hashCode() == s.hashCode())
{
calculate();
}
}
if (Edtinch21.getText().toString().length() <= 0)
{
Edtinch21.setError("Input Inch");
}
else if (Edtinch22.getText().toString().length() <= 0)
{
Edtinch22.setError("Input Inch");
}
else if (Edtfeet2.getText().toString().length() <= 0)
{
Edtfeet2.setError("Input feet");
}
else if (Edtquan2.getText().toString().length() <= 0) {
Edtquan2.setError("Input Quantity");
}
else
{
if (Edtquan2.getText().hashCode() == s.hashCode())
{
calculate2();
}
}
if (Edtinch31.getText().toString().length() <= 0)
{
Edtinch31.setError("Input Inch");
}
else if (Edtinch32.getText().toString().length() <= 0)
{
Edtinch32.setError("Input Inch");
}
else if (Edtfeet3.getText().toString().length() <= 0)
{
Edtfeet3.setError("Input feet");
}
else if (Edtquan3.getText().toString().length() <= 0) {
Edtquan3.setError("Input Quantity");
}
else
{
if (Edtquan3.getText().hashCode() == s.hashCode())
{
calculate3();
}
}
if (Edtinch41.getText().toString().length() <= 0)
{
Edtinch41.setError("Input Inch");
}
else if (Edtinch42.getText().toString().length() <= 0)
{
Edtinch42.setError("Input Inch");
}enter code here
else if (Edtfeet4.getText().toString().length() <= 0)
{
Edtfeet4.setError("Input feet");
}
else if (Edtquan4.getText().toString().length() <= 0) {
Edtquan4.setError("Input Quantity");
}
else
{
if (Edtquan4.getText().hashCode() == s.hashCode())
{
calculate4();
}
}
}
相关代码将使您得到更快更好的响应。@Rohit5k2:我已经上传了,请帮助me@rfornal:我已经上传了,请帮助我你为什么在这里使用TextWatcher?@Rohit5k2:实际上我在这个应用中使用了多个Edittext,我希望在Edittext中输出,而不使用任何按钮。