android - Virtual keyboard does not open when dynamically inserting an EditText view into a Listview -


i'm struggeling issue drives crazy. found comparable issues in forums, not quite same one. hope has brilliant idea how solve this. or tell me i'm doing wrong. ;-)

the setup:

i have listview. following xml code represents child elements:

<?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   = "wrap_content"     android:id              = "@+id/container">      <edittext android:id            = "@+id/child"               android:layout_width  = "300dp"               android:layout_height = "wrap_content" />  </linearlayout> 

it linearlayout in turn has edittext view inside. following code adds 1 child list. since edittext view smaller linearlayout embedded, testing i've attached click listener empty space of (first) child's linearlayout. when clicking on child second child inserted listview:

public class keyboard_bug extends listactivity {     static bugadapter madapter;     static string [] mnamearray = new string [2];     static int mcount;       public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          mnamearray[0] = "entry 1";         mcount = 1;         madapter = new bugadapter(this);         setlistadapter(madapter);     }      public static class bugadapter extends baseadapter     {         final layoutinflater minflater;         edittext mview;          public bugadapter(context context)     { minflater = layoutinflater.from ( context );   }         public int  getcount  ()               { return mcount  ; }         public long getitemid ( int position ) { return position; }         public object getitem ( int position ) { return mnamearray[position]; }          public view getview( int position, view convertview, viewgroup parent )         {             if ( convertview == null )                 convertview = minflater.inflate(r.layout.child, parent, false);              mview = (edittext) convertview.findviewbyid(r.id.child);             mview.settext(mnamearray[position]);              // focus 1 //          if ( mnamearray[position].equals("entry 1") ) //              mview.requestfocus();              // focus 2             if ( mnamearray[position].equals("entry 2") )                 mview.requestfocus();              linearlayout ll = (linearlayout) convertview.findviewbyid(r.id.container);              ll.setonclicklistener(new view.onclicklistener()     {                           public void onclick(view v) {                     mnamearray[mcount] = "entry 2";                     mcount++;                     madapter.notifydatasetchanged();             }});              return  convertview;         }        } } 

when use (commented out) code section comment "get focus 1", works perfect. "entry 1" gets focus , keyboard pops up.

the issue:

when onclick handler inserts second child , use code section comment "get focus 2", second child's edittext view obtains focus (that's fine), keyboard not open. can click on newly created edittext, , though cursor blinking cannot open keyboard. way select first edittext , select second edittext again. keyboard opens.

i tried already:

inputmethodmanager mgr = (inputmethodmanager) getsystemservice(context.input_method_service); mgr.showsoftinput(edittext, inputmethodmanager.show_implicit); 

as posted in different forums, didn't work. thing worked was:

mgr.togglesoftinput ( 0, 0 ); 

but of course not right approach, since in case keyboard open, closed.

i apreciate suggestions! thanks!

bernd

use code on edittext click event :

inputmethodmanager m = (inputmethodmanager) getsystemservice(context.input_method_service);   if(m != null){       m.togglesoftinput(0, inputmethodmanager.show_implicit);    }  

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -