Android Button always takes two clicks to fire onClick() -
i have relativelayout inside of scrollview contains button , textviews , edittexts.
in xml layout file, defining android:onclick takes 2 clicks of button fire event. button gets focus on first click , fires onclick event on second click. have tried setting focusable , focusableintouchmode both false behavior doesn't change.
here layout file:
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".densityactivity" > <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview ... <textview ... <textview ... <edittext ... <button android:id="@+id/ad_button_calculate" android:layout_width="112dp" android:layout_height="wrap_content" android:layout_below="@id/ad_edit_obs_temp" android:layout_alignparentright="true" android:layout_margintop="20pt" android:paddingleft="6pt" android:onclick="onclick" android:focusable="false" android:focusableintouchmode="false" android:text="@string/button_calculate" /> <textview ... </relativelayout> </scrollview>
any ideas or suggestions why focusable , focusableintouchmode don't seem anything?
i thought might onclick() method not doing should reduced simple see , behaves same. here simplified onclick():
public void onclick(view view) { new alertdialog.builder(this).settitle("argh").setmessage("watch out!").setneutralbutton("close", null).show(); }
ok, found it. was, of course, own mistake. @ end of oncreate method doing this:
// set focus calculate button keyboard won't show automatically button calcbutton = (button)findviewbyid( r.id.ac_button_calculate ); calcbutton.setfocusable( true ); calcbutton.setfocusableintouchmode( true ); calcbutton.requestfocus();
so of course, no matter did in xml file, overriding in code. instead, used hide keyboard:
getwindow().setsoftinputmode( windowmanager.layoutparams.soft_input_state_hidden );
which works great.
Comments
Post a Comment