android - Enabling the Edittext on selecting Item from Spinner -


hello friends trying enable edittext depending upon selection of records.the xml file below:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >      <spinner          android:id="@+id/per_id"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:spinnermode="dropdown"         android:gravity="center"         android:layout_margintop="20dp"/>      <spinner android:id="@+id/columntoupdate"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:spinnermode="dialog"         android:gravity="center"         android:layout_margintop="20dp"/>      <edittext          android:id="@+id/entertoupdatestring"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:gravity="center"         android:layout_margintop="20dp"         android:inputtype="text"         android:hint="@string/enterthetexthere"/>     <edittext          android:id="@+id/entertoupdateint"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:gravity="center"         android:layout_margintop="20dp"         android:inputtype="number"         android:hint="@string/enterthenumberhere"/>       <button          android:id="@+id/clicktoupdate"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:text="@string/clicktoupdate"/> </linearlayout> 

and java code applying below :-

package com.indianic.databaseprac;  import java.util.arraylist; import java.util.list;  import android.app.activity; import android.database.cursor; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.onitemselectedlistener; import android.widget.arrayadapter; import android.widget.button; import android.widget.edittext; import android.widget.spinner;  public class updatefrom25table extends activity {     string id, column, text;     edittext integertext;     edittext stringtext;        @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.update_from_25_table);          stringtext = (edittext) findviewbyid(r.id.entertoupdatestring);         integertext = (edittext) findviewbyid(r.id.entertoupdateint);         stringtext.setvisibility(view.gone);         integertext.setvisibility(view.gone);         button updatebutton = (button) findviewbyid(r.id.clicktoupdate);          // here setting spinner taking content of         // table per_id having unique ids , setting spinner         spinner spinnerid = (spinner) findviewbyid(r.id.per_id);          final database25tablehandler db = new database25tablehandler(                 getapplicationcontext());         list<string> ids = db.gettingid();         arrayadapter<string> dataadapter = new arrayadapter<string>(this,                 android.r.layout.simple_spinner_item, ids);         dataadapter                 .setdropdownviewresource(android.r.layout.simple_dropdown_item_1line);         spinnerid.setadapter(dataadapter);          // here setting column names in second spinner         // of cursor.         spinner spinnercolumn = (spinner) findviewbyid(r.id.columntoupdate);          list<string> column = db.getcolumnname();         arrayadapter<string> dataadaptercolumn = new arrayadapter<string>(this,                 android.r.layout.simple_spinner_item, column);         dataadaptercolumn                 .setdropdownviewresource(android.r.layout.simple_dropdown_item_1line);         spinnercolumn.setadapter(dataadaptercolumn);           final string spinnerselectedid = (string) spinnerid.getselecteditem();         final string spinnerselectedcolumn = (string) spinnercolumn                 .getselecteditem();           spinnercolumn.setonitemselectedlistener(new onitemselectedlistener() {              @override             public void onitemselected(adapterview<?> parent, view view,                     int pos, long id) {                 log.d("testing", parent.getitematposition(pos).tostring());  // todo auto-generated method stub                 if(parent.getitematposition(pos).tostring() == "reg_id") {                     //integertext.setenabled(true);                     log.d("testing", "looooggggg");                     integertext.setvisibility(view.visible);                     text = integertext.gettext().tostring();                  } else if (parent.getitematposition(pos).tostring() == "first_name") {                     //stringtext.setenabled(true);                     stringtext.setvisibility(view.visible);                     text = stringtext.gettext().tostring();                  }             }              @override             public void onnothingselected(adapterview<?> arg0) {                 // todo auto-generated method stub              }         });         // here setting items selected in string in         // order perform update process.          updatebutton.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                  db.updaterow(spinnerselectedid, spinnerselectedcolumn, text);                 db.close();             }         });      }   } 

here when selecting reg_id spinner not entering first if part log.d("testing", "looooggggg"); not printed

try this..

if comparing string should use .equels

if(parent.getitematposition(pos).tostring().equels("reg_id")) {                     //integertext.setenabled(true);                     log.d("testing", "looooggggg");                     integertext.setvisibility(view.visible);                     text = integertext.gettext().tostring();                  } else if (parent.getitematposition(pos).tostring().equels("first_name")) {                     //stringtext.setenabled(true);                     stringtext.setvisibility(view.visible);                     text = stringtext.gettext().tostring();                  } 

== compares 2 references (for non-primitives, is) - i.e. tests whether 2 operands refer same object.

however, equals method can overridden - 2 distinct objects can still equal

edit

if(parent.getitematposition(pos).tostring().equalsignorecase("reg_id") || parent.getitematposition(pos).tostring().equels("first_name")){ } 

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -