私はAndroidについて非常に新しいので、私は物事を学ぼうとしています。もし私が愚かな質問をしているなら、私は言い訳をします。
これは私のAndroidアプリの外観です。ユーザーがAndroid TextWatcherで新しい値を入力した場合の最終値の更新方法
私は彼が好きな場合、ユーザが(例えば3%)のような値を追加できる新しいedittextフィールドを追加します。次に、ユーザが入力した値(たとえば3%)をResult TextViewの合計値で計算し、その値を[Sub Value]テキストビューフィールドに表示する必要があります。たとえば、最終結果textviewの合計値が1000で、ユーザー入力が3%の場合、Sub Valueフィールドには30が表示されます。その後、Final Resultを1030に更新する必要があります。事前のおかげで
public class AddTwo extends AppCompatActivity {
EditText edit1, edit2, edit3;
EditText edit4, edit5, edit6;
TextView textViewSub1, textViewSub2, textViewSub3, textViewSub4, textViewResult;
TextView nbtText;
EditText editNbt, vat;
Button btnNext;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_add_two);
btnNext = (Button) findViewById(R.id.button2);
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
gotoNextPage();
}
private void gotoNextPage() {
Intent i = new Intent(AddTwo.this, NewClass.class);
startActivity(i);
}
});
/*Vat variables*/
editNbt = (EditText) findViewById(R.id.Edittext11);
/*First row variables*/
edit1 = (EditText) findViewById(R.id.editText1);
edit2 = (EditText) findViewById(R.id.editText2);
edit3 = (EditText) findViewById(R.id.editText3);
textViewSub1 = (TextView) findViewById(R.id.TextViewsub1);
/*Second row variables*/
edit4 = (EditText) findViewById(R.id.editText5);
edit5 = (EditText) findViewById(R.id.editText6);
edit6 = (EditText) findViewById(R.id.editText7);
textViewSub2 = (TextView) findViewById(R.id.TextViewsub2);
/*Final Total TextView variable*/
textViewResult = (TextView) findViewById(R.id.textView_result);
/*NBT value variable*/
nbtText = (TextView) findViewById(R.id.textViewNbt12);
edit1.addTextChangedListener(new LashCustomTextWatcher());
edit2.addTextChangedListener(new LashCustomTextWatcher());
edit3.addTextChangedListener(new LashCustomTextWatcher());
edit4.addTextChangedListener(new LashCustomTextWatcher());
edit5.addTextChangedListener(new LashCustomTextWatcher());
edit6.addTextChangedListener(new LashCustomTextWatcher());
textViewResult.addTextChangedListener(new LashCustomTextWatcher());
}
public class LashCustomTextWatcher implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
textViewResult.setText(lashCalculate());
}
@Override
public void afterTextChanged(Editable editable) {
textViewResult.setText(lashCalculate());
}
}
public String lashCalculate() {
//declaring variables
double row1_value = 0;
double row2_value = 0;
//Optional Values
double row_nbt_value = 0;
double row1_value_new = 0;
DecimalFormat df = new DecimalFormat("0.00##");
//calculate first row
if (!edit1.getText().toString().equals("") && !edit2.getText().toString().equals("")) {
double num1 = Double.parseDouble((edit1.getText().toString()));
double num2 = Double.parseDouble((edit2.getText().toString()));
row1_value = num1 * num2;
double num3 = 0;
if (!edit3.getText().toString().equals("")) {
num3 = Double.parseDouble((edit3.getText().toString()));
row1_value = (((100 - num3) * num2) * num1)/100;
}
textViewSub1.setText(df.format(row1_value));
}
//calculate second row
if (!edit4.getText().toString().equals("") && !edit5.getText().toString().equals("")) {
double num4 = Double.parseDouble((edit4.getText().toString()));
double num5 = Double.parseDouble((edit5.getText().toString()));
row2_value = num4 * num5;
double num6 = 0;
if (!edit6.getText().toString().equals("")) {
num6 = Double.parseDouble((edit6.getText().toString()));
row2_value = (((100 - num6) * num5) * num4)/100;
}
textViewSub2.setText(df.format(row2_value));
}
/* ========================================================================== */
//calculate the NBT
double numNbt = 0;
if (!editNbt.getText().toString().equals("")) {
numNbt = Double.parseDouble(editNbt.getText().toString());
row_nbt_value = numNbt/100;
if (row1_value !=0){
row1_value_new = row1_value * row_nbt_value;
}
nbtText.setText(df.format(row1_value_new));
}
return df.format(row1_value_new + row2_value);
}
}
これは私LogCatです:
9月12日09:55:51.908 1624年から1624年/? I/InstallerConnection:接続中... 09-12 09:55:51.936 1624-1624 /? I/InstallerConnection:切断中... 09-12 09:55:51.978 1624-1624/system_process I/Installer接続:接続中... 09-12 09:56:04.447 2433-2502/com.google.android.gms I/FA-SVC:アプリケーション計測開始、バージョン:11055 09-12 09:56:04.530 2433-2922/com.google.android.gms I/FA-SVC:このインスタンスはアップローダとしてマークされています 09 -12 09:56:04.794 2433-2441/com.google.android.gms W/SQLiteConnectionPool:データベース '/data/user/0/com.google.android.gms/databases/networkstatistics.sqlite'のSQLiteConnectionオブジェクトがありました漏れた!進行中のトランザクションを正常に終了するようにアプリケーションを修正し、不要になった時点でデータベースを閉じるようにしてください。 09-12 09:56:14.889 2433-2441/com.google.android.gms W/SQLiteConnectionPool:データベース '/data/user/0/com.google.android.gms/databases/metrics.dbのSQLiteConnectionオブジェクト.16 'が流出した!進行中のトランザクションを正常に終了するようにアプリケーションを修正し、不要になった時点でデータベースを閉じるようにしてください。 09-12 09:56:14.890 2433-2441/com.google.android.gms W/SQLiteConnectionPool:データベース '/data/user/0/com.google.android.gms/databases/help_responses.dbのSQLiteConnectionオブジェクト.18 'が流出した!進行中のトランザクションを正常に終了するようにアプリケーションを修正し、不要になった時点でデータベースを閉じるようにしてください。 09-12 09:56:14.892 2433-2441/com.google.android.gms W/SQLiteConnectionPool:データベース '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.dbのSQLiteConnectionオブジェクト'が流出した!進行中のトランザクションを正常に終了するようにアプリケーションを修正し、不要になった時点でデータベースを閉じるようにしてください。
計算です。 –
@J Ramesh、はい私は同じ方法で計算しますが、うまくいきません。私に提案してください。 – Lash
xmlをどうにかしてください。 –