0

私は問題があります。日付がある 2 つの Edittext があります。addTextChangeListenerテキストの変更を確認するために使用しています。これはコードです:

tvDateFrom.addTextChangedListener(new TextWatcher() {

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        Date dateFromPicker = null;
        if(listOfSBPData!=null)
            try {
                dateFromPicker = sdf.parse(tvDateFrom.getText().toString());
                String dt = tvDateFrom.getText().toString();
                SimpleDateFormat dateFormat = new SimpleDateFormat( "dd-MM-yyyy" );
                Calendar cal = Calendar.getInstance();
                cal.setTime( dateFormat.parse( tvDateFrom.getText().toString() ) );
                cal.add( Calendar.DATE, 7 );
                  int  year = cal.get(Calendar.YEAR);
                  int  month = cal.get(Calendar.MONTH);
                  int day = cal.get(Calendar.DAY_OF_MONTH);
                    tvDateTo.setText(""+day+"-"+(month+1)+"-"+year);
                    addSBPSeries();
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterTextChanged(Editable s) {


    }
});

tvDateTo.addTextChangedListener(new TextWatcher() {

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        Date dateFromPicker = null;
        if(listOfSBPData!=null)
            try {
                dateFromPicker = sdf.parse(tvDateTo.getText().toString());
                String dt = tvDateTo.getText().toString();
                SimpleDateFormat dateFormat = new SimpleDateFormat( "dd-MM-yyyy" );
                Calendar cal = Calendar.getInstance();
                cal.setTime( dateFormat.parse( tvDateTo.getText().toString() ) );
                cal.add( Calendar.DATE, 7 );
                  int  year = cal.get(Calendar.YEAR);
                  int  month = cal.get(Calendar.MONTH);
                  int day = cal.get(Calendar.DAY_OF_MONTH);
                    tvDateFrom.setText(""+day+"-"+(month+1)+"-"+year);
                    addSBPSeries();
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterTextChanged(Editable s) {


    }
});

tvDateFrom で日付を変更すると、tvDateTo editview から日付に 1 週​​間追加されます。tvDateTo に日付を追加すると、日付から 1 週間減算されます。テキストウォッチャーが1つしかない場合、すべてが正常に機能します。例: tvDateFrom にのみ textChangeListener がある場合、すべて正常に動作しますが、2 番目に textchangelistener を追加するとエラーが発生します。

03-17 14:55:04.440: E/AndroidRuntime(25190): FATAL EXCEPTION: main
03-17 14:55:04.440: E/AndroidRuntime(25190): java.lang.StackOverflowError
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.graphics.Paint.getTextRunAdvances(Paint.java:1681)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.text.MeasuredText.addStyleRun(MeasuredText.java:170)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.text.MeasuredText.addStyleRun(MeasuredText.java:210)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.text.StaticLayout.generate(StaticLayout.java:283)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.text.DynamicLayout.reflow(DynamicLayout.java:298)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.text.DynamicLayout.<init>(DynamicLayout.java:174)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.makeSingleLayout(TextView.java:6613)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.makeNewLayout(TextView.java:6495)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.checkForRelayout(TextView.java:7064)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3479)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3335)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.EditText.setText(EditText.java:90)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3310)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at MeasurementsChart$20.onTextChanged(AmmsMeasurementsChart.java:572)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.sendOnTextChanged(TextView.java:8155)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3482)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3335)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.EditText.setText(EditText.java:90)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3310)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at MeasurementsChart$21.onTextChanged(AmmsMeasurementsChart.java:611)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.sendOnTextChanged(TextView.java:8155)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3482)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3335)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.EditText.setText(EditText.java:90)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3310)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at MeasurementsChart$20.onTextChanged(AmmsMeasurementsChart.java:572)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.sendOnTextChanged(TextView.java:8155)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3482)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3335)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.EditText.setText(EditText.java:90)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3310)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at MeasurementsChart$21.onTextChanged(AmmsMeasurementsChart.java:611)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.sendOnTextChanged(TextView.java:8155)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3482)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3335)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.EditText.setText(EditText.java:90)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3310)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at MeasurementsChart$20.onTextChanged(AmmsMeasurementsChart.java:572)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.sendOnTextChanged(TextView.java:8155)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3482)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3335)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.EditText.setText(EditText.java:90)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3310)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at MeasurementsChart$21.onTextChanged(AmmsMeasurementsChart.java:611)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.sendOnTextChanged(TextView.java:8155)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3482)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3335)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.EditText.setText(EditText.java:90)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3310)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at MeasurementsChart$20.onTextChanged(AmmsMeasurementsChart.java:572)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.sendOnTextChanged(TextView.java:8155)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3482)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3335)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.EditText.setText(EditText.java:90)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3310)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at MeasurementsChart$21.onTextChanged(AmmsMeasurementsChart.java:611)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.sendOnTextChanged(TextView.java:8155)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3482)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3335)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.EditText.setText(EditText.java:90)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.setText(TextView.java:3310)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at MeasurementsChart$20.onTextChanged(AmmsMeasurementsChart.java:572)
03-17 14:55:04.440: E/AndroidRuntime(25190):    at android.widget.TextView.sendOnText
4

1 に答える 1

1

ここで私の答えを試してください:

https://stackoverflow.com/a/7222993/557179

ニーズに合わせて調整してください。

それが役に立てば幸い。

于 2013-03-17T14:01:00.863 に答える