java - How to update a TextView on ButtonClick with Spinner(s) values -


I'm trying to populate a TextView based on the currently selected options in 3 spinners but cant find out This is how to bring the updated function together to retrieve the values ​​selected from the spinners. Here is my current code (quite messy but I am just learning Java),

  Public class extends ageFun activity {private string [] dayNames; Private string [] years old; Personal Final Static Int START_YEAR = 1990; Private static textview text disp. Personal Button Calcubutan; Private spin spinner, spinner year, spinner month; Private statue array adapter & lt ;? & Gt; Month adapter, day adapter, year adapter; Private int year, month, day; /** Called when the activity is first created. * / @ Override Crate on Public Zero (Bundle Saved Instantstate) {Super. Contents (Saved Instantstate); SetContentView (R.layout.main); Year = 2000; Months = 1; Day = 1; TextDisp = (TextView) findViewById (R.id.textView1); Calcbutton = (Button) findViewById (R.id.button); CalcButton.setOnClickListener (New OnClickListener) {public void onClick (see v) {// Click Action on AgeFun.updateAge click (year, month, day);}}); // month spinner spinner month = (spinner) find VVBIID (RID spinner first); MonthAdapter = ArrayAdapter.createFromResource (this, R. nightmothlist, android.R.layout.simple_spinary_item); MonthAdapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item); SpinnerMonth.setAdapter (monthAdapter); // day spinner daemans = new string [31]; For (int i = 1; i & lt; = 31; ++ i) {dayNames [i-1] = integer.txtring (i); } Spinner == (spinner) Find VVIBID (RID Spinner Second); Day adapter = new Arrayheader & lt; Foursquence & gt; (This, Android .R.Lite.Simple_spinner_item, Dednames); SpinnerDay.setAdapter (dayAdapter); // year spinner yearre = new string [40]; For (int i = 0; i <40; ++ i) {salarre [i] = integer. Tasting (START_YEAR + i); } Spinner Yer = (Spinner) Find VViBID (RID Spinner Tired); Year Adapter = New Arrayheader & lt; Foursquence & gt; (This, Android .R.Leoutout.Simple_spinney_item, Salary); SpinnerYear.setAdapter (yearAdapter); UpdateAge (2000,1,1); } Private Static Zero UpdateAge (int year, int month, int day) {date db = new gregorian calendars (year, month, day) .getTime (); Date currDate = new date (); Longevity = (currDate.getTime () - dob.getTime ()) / (1000 * 60 * 60 * 24) / 365; TextDisp.setText ("yours" + long.stosting (age) + "year old"); }  

}

Any help with this will be great.

TIA

You can get the value of the current spinner in it. Since you have filled your array adapter with Charseequence, there will be selected items in this way.

Alternatively, you should be able to use an array adapter and deal with direct input. I believe spinner has used the type of string method of the object.

Edit: I remembered the important part, add one of the items to each spinner selected listener, that is:

  adapters like. OnTam-selected listener = new adapterview. OnTame Selected Listener () {onItemSelected (Adapterview> Lieutenant;? & Gt; parent, see view, status of the int, long id} {updateAge (); }} Day adapters.Seaton items selectedListered (listener); ... Private Zero updateAge () {int day = spinnerDay.getSelectedItem (); ....}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -