Search code examples
javaandroiddictionarygettext

Get the text from a text view every time it updates


I have an app for android studio. a map app where I find my coordinates and I set them to 2 textviews. as you imagine they change when I move. The shows I want to get these values from these 2 textviews so I can set them to the marker to find me in the map fragment I have made.

    double lat11 = Double.parseDouble(this.lat.getText().toString());
    double long11 = Double.parseDouble(this.longi.getText().toString());


    LatLng loc = new LatLng(lat11,long11);
    googleMap.addMarker(new MarkerOptions().position(loc)
            .title(""));
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(loc));

As you also imagine the code above takes only the default values of the 2 textviews!

Anyone's opinion will be thankful!!


Solution

  • EditText textview = (EditText) findViewById(R.id.text_view);
    
    textview.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                 //Called after before changed
            }
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                //Called after on changed
            }
    
            @Override
            public void afterTextChanged(Editable s) {
                //Called after text changed
            }
        });