android - TextChanged Listener -


I'm still new to Android development and what I want to do is create a listener, which will include two textview objects. Area and perimeter width and height edit text objects are when I have entered the width and height, the circumference and area value should be shown in real time based on the methods of calcarea and calc parameter. The code I used for the listener is an example that I found here. My code:

  package com.jtryon.rectanglecalc; Import android.support.v7.app.ActionBarActivity; Import android.support.v7.app.ActionBar; Import android.support.v4.app.Fragment; Import android.text.Editable; Import android.text.TextWatcher; Importroid.os.Bundle; Import android.view.LayoutInflater; Import android.view.Menu; Import android.view.MenuItem; Import android.view.View; Import android.view.ViewGroup; Import android.widget.EditText; Import android.widget.TextView; Import android.os.build; Public Class Main Activity Extends ActionBarActivity {//} in the fields / variables that this file is global in double width; Double height; Double area; Double perimeter; // XML editingText widthAdit "handles" for objects; EditText HeightAdit; TextView areaText; TextView perimText; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main); // Set up handle width edit = (edit text) Find VVBID (Ridwidth_Aidit); Height edit = (edit text) Find VVBID (RID .ite_edit); AreaText = (TextView) findViewById (R.id.area_value); PerimText = (TextView) findViewById (R.id.perim_value); widthEdit.addTextChangedListener (New TextWatcher ()) Override public {{TODO} after the {@TextChanged (editable ARB0) read out the Zune {// TODO auto generated method stub // width width Edward String widthString = widthEdit.getText (). toString (); // Change the string to a double if (width string) .Length ()> gt; {width = double.parseDouble (widthString);} // read height of height; type string height; heightEdit.getText (). ToString ( ); If (HeightString.length ()> gt; {height = double.prps double (height string);} / / field area double area = calcutta (); // compute perimeter double perim = calcPerim () Set the label for; AreaText; Set the label for areaText.setText (Double.toString (Region)); // perimText perimText.setText (DoubleTosting (Perim));} @TextCha Override public zeros before nged (over the squares, int start, int count, int) {// Todo auto-generated method stub} Override public null at @TextChanged (foursquences s, int start, before int , Int counting) {// Tudo Auto Generated Method Stub}}); } Double calcarea () {return width * height; } Double Calciparim () {returns 2 * width * height; }}   

user interface < P>

Define it under the coach in your editor

  youredittext. addTextChangedListener (New TextWatcher) {@TextChanged override public wired before {@ThreadSquanes s, int start, int before, int count} @TextChanged (Charsequences s, int start, int count, int aft) } @TextChanged (editable) Override Public Zero S) {// Call your Function Here Here Your Fun Shn ();}});    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -