0
私は通貨換算をWeb上で見つけたチュートリアルに基づいてドルとユーロの間にしようとしています。問題はチュートリアルが2つのラジオボタンを使用して変換、注文の参照最初にどのメソッドを呼び出すかをプログラムに伝えます。私は、プログラムが2つのラジオボタンから独立して、即座に変換を行うようにしたいと思います。たとえば、ユーロまたはドルの数値を書き込む場合です。テキストビュー...次に、 2つの方法があり、同時に入力を表示する方法がない限り、私はできません。私の質問は、私がconvertボタンを押すと同時に2つのeditTextビューを更新する方法です?ありがとうございます。通貨コンバータの入力を瞬時に更新するには?
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ConvertorActivity extends Activity {
TextView dollars;
TextView euros;
Button convert;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
dollars = (TextView)this.findViewById(R.id.dollars);
euros = (TextView)this.findViewById(R.id.euros);
convert = (Button)this.findViewById(R.id.convert);
convert.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
convertBoth();
}
});
}
public void convertBoth(){
convertDollarsToEuros();
convertEurosToDollars();
}
protected void convertDollarsToEuros() {
double val = Double.parseDouble(dollars.getText().toString());
// in a real app, we'd get this off the 'net
euros.setText(Double.toString(val*0.67));
}
protected void convertEurosToDollars() {
double val = Double.parseDouble(euros.getText().toString());
// in a real app, we'd get this off the 'net
dollars.setText(Double.toString(val/0.67));
}
}
....しかし、どのような:
は内部
TextWatcher
のクラスを定義します。それ以上の2種類の通貨について...どうすればいいですか? – Stefan3つ目の通貨として円があるとします。円のために 'TextWatcher'を新しい' TextView'に添付する必要があります。次に、 'convertDollarsToEuros'を' convertDollarsToOthers'に変更し、円に対する為替レートで 'dollar'と' euros'の両方を更新します。 'convertEurosToOthers'と' convertYenToOthers'を使って繰り返します。 – chiuki
それを持って...ありがとう – Stefan