score:8
Okay so I finally figured out what caused the problem, by myself. I can't believe I missed such an obvious issue. The thing that caused problem wasn't focus, but the method itself. In my XML file I called onClick method by android:onClick="onClick" and then I also added a buttonlistener inside the onClick method to java code.
All I did was remove the buttonlistener and there's no more double clicking neccessary! So if anyone has this problem in future simply make sure you don't have an onClick method AND buttonlistener at the same time.
Wrong code:
public void submitQuantityButton (View v){
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
.
.
. //REST OF THE CODE
To make it work I simply deleted the onclick listener, leaving only:
public void submitQuantityButton (View v){
.
.
. //REST OF THE CODE
score:-1
Simply use getText() to get text from EditText And then set text of TextView using setText().
score:0
try this once
UPDATED
override
onResume
method in your activity
and then clear focus from your edittext and set focus to your main layout
edittext.clearFocus();
layout.requestFocus();
or
button.requestFocus();
if the problem is with virtual keyboard it might help you
in your AndroidManifest.xml
file inside your Activity
tag put this line
android:windowSoftInputMode="stateHidden"
score:0
I had the same problem as the OP. I tried all the focus-related suggestions, but none of them worked every time for me.
I tried removing the NavigationDrawer
from my layout, but that didn't work.
Lastly, I tried replacing my CoordinatorLayout
with a LinearLayout
and now my buttons click first time every time. Could be worth a try.
score:0
By adding the following lines :
<Button
android:id="@+id/sauvegarder"
android:text="Sauvegarder"
android:layout_gravity="center"
android:background="@color/colorAccent"
android:layout_margin="@dimen/fontmargin"
style="@style/edit"
android:gravity="center"
android:textColor="@color/colorPrimary"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
/>
in my xml file it works perfectly !
score:2
Sometime I had it problem when click on btn or txt or edt on the fragment, and realy helps use instead .setOnClickListener() need .setOnTouchListener like this example:
txtClose.setOnTouchListener((v, event) -> {
// do staff...
return false;
});
score:3
If you are inflating view to another one, try to set on parent view:
view.setFocusable(false);
worked for me.
score:50
My problem was the Button
XML defining:
android:focusableInTouchMode="true"
Remove this attribute and the button doesn't require being touched twice. It appears as though the first touch is consumed to assign focus on the button and the second then triggers the OnClickListener
.
Note that the Button works without issue with the android:focusable="true"
attribute.
Source: stackoverflow.com
Related Query
- I have to click the button twice for it to work
- Maven 3 Eclipse Kepler is it necessary to have the environment variable to work for embedded Maven?
- When I click the Button it doesn't work (Android)
- What's the meaning of this in Eclipse: "Path for project must have only one segment."
- the user operation is waiting for background work to complete
- Does eclipse have a debugger "step into selected" option that prompts for the method to step into?
- I have eclipse with pydev and i set the background to black and text white. now when i click on any word, is highlighted in a yellow color
- How to fix the error: test source folder 'src/test/java' in project must have an output folder that is not also used for main source"?
- How do I toggle the menu button icon and tooltip text for an Eclipse plugin?
- Why won't the Back button work in this Android webview?
- How to have Eclipse Java EE automatically generate the exploded WAR for a web project?
- button click does not change the textview value
- Why won't the GWT designer for eclipse work with GXT 3 widgets?
- Pydev: Where do I have to add the path for an external lib (usr/local/mysql/lib/libmysqlclient)?
- Is it possible to have multiple people work on the same Eclipse project at once? (Like Google Docs)
- How can I use a javaScript function to call the rowEditor button for the latest row added to my datatable?
- how can i create a custom button for my android application without the button becoming blurred?
- In Eclipse, How does one specify the "android:id" for a button when creating the layout dynamically in the .java file
- Eclipse PyDev doesn't shut down interpreter when you click the little red button
- Is there any other way to add an ActionListener to a button using windowbuilder (eclipse) in design mode than to double click on the button?
- How to make Bluetooth turn on and search for devices when i click the app?
- Error setonclickListener undefined for the type button
- Logger is printing the message twice and some times even more for the whole program
- How does the enable and disable options work for these actions in eclipse?
- The font for inactive UI elements in Eclipse look "doubled," or as if they have shadows
- Trying to develop mods for minecraft, but can't get the SetupdecompWorkspace.bat to work
- How to create my own button for the Eclipse tool-bar?
- Android: How does one go about having the user click a button to create (not go to) a new activity
- How to make it work the back button in android webview?
- Have to touch back button twice to go to previous activity
More Query from same tag
- java GEF independ from Eclipse IDE
- invalid location of tag a, jsp page in eclipse
- Is there a way to specify $GlobalRev$ in a file using Subclipse for Eclipse
- Android: pixel-perfect layouts for each resolution
- return a default timestamp object instead of null
- Restful Web Service runs in Shell but not Eclipse indigo,it gives class not found exception
- Eclipse RCP application with Spring Beans
- Auto activation triggers for C/C++ in eclipse
- spring-web maven dependency not being published with eclipse
- What does this eclipse error mean: "path for project must have only one segment"?
- Why do the source folders in package explorer appear in not alphabetical order
- Cursor with Semi-Transparency / Anti-Aliasing
- Android Min SDK Version vs. Target SDK Version
- How To Display Image Taken In A New Activity
- c++0x compiles but eclipse editor errors even with -gnu++0x discovery
- Intellij IDEA: wrapping certain widget in a container in XML file
- EMF Eclipse Installation
- Eclipse: add javadoc
- Show accept certificate dialog with subclipse
- How do you enable C++11 syntax in Eclipse Neon?
- How to get package icon in eclipse?
- Groovy failures after upgrading eclipse
- Having an ERROR: java.lang.ClassNotFoundException
- Eclipse Oxygen very slow server startup when debug on GAE projects. Server process hangs in a stopping pending state
- JFace ProgressMonitorDialog not showing progress bar if fork is false
- eclipse didn't do apk with proguard.cfg
- Switch Case error. Eclipse IDE for Android development on Mac : Change workspace compliance to JRE 1.7
- Count Down Timer?
- How To setup IBM Mobile First version 7.1 in eclipse - IBM mobile first not available in eclipse marketplace
- Terminate debug on device