Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6237541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:02:51+00:00 2026-05-24T11:02:51+00:00

UPDATE I’ve solved the clicking issue by removing the two focusable lines from the

  • 0

UPDATE

I’ve solved the clicking issue by removing the two focusable lines from the button style and using the onClick event handler to call requestFocusFromTouch();

Unfortunately I’m left with an issue that requestFocusFromTouch() focuses the wrong button. It always focuses the first button not the button I call the method on. Is this an android bug or expected behaviour and what I can I do for a work around?

The code now looks like this for the onClick event

public void onClick(View v) {
    switch (v.getId()) {
            case R.id.btn_home:
                Intent i = new Intent(this, QuizMenu.class);
                startActivity(i);
                v.requestFocusFromTouch();
            break;
            case R.id.btn_support:
                Intent i1 = new Intent(this, Support.class);
                startActivity(i1);
                v.requestFocusFromTouch();
                View btnSupport = findViewById(R.id.btn_support);
                btnSupport.setSelected(true);
                btnSupport.requestFocusFromTouch();
            break;
            // More buttons go here (if any) ...
    }
}

END OF UPDATE

I have an android button that has the following style

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MnuBtnStyle">
        <item name="android:ellipsize">marquee</item>
        <item name="android:scrollHorizontally">true</item>
        <item name="android:focusable">true</item>
        <item name="android:focusableInTouchMode">true</item>
        <item name="android:singleLine">true</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_marginTop">1dip</item> 
        <item name="android:layout_marginBottom">1dip</item>
        <item name="android:textSize">10dp</item>
        <item name="android:layout_weight">1</item>
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
    </style>
</resources>

I have an on click listener that looks like this

public void onClick(View v) {
    switch (v.getId()) {
            case R.id.btn_home:
                Intent i = new Intent(this, HomeScreen.class);
                startActivity(i);
            break;
            // More buttons go here ...
    }
}

I have an image on the button and the selector looks like this

<?xml version="1.0" encoding="utf-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
        android:drawable="@drawable/ic_tab_home_pressed" /> <!-- pressed -->
    <item android:state_focused="true"
        android:drawable="@drawable/ic_tab_home_pressed" /> <!-- pressed -->
    <item android:drawable="@drawable/ic_tab_home_unpressed" /> <!-- default/unchecked -->
</selector>

The layout that uses the button and the button looks like this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:id="@+id/top_menu_bar"
      android:layout_marginTop="2dip" 
      android:padding="0dip"
      android:background="@android:drawable/bottom_bar"
      android:layout_alignParentTop="true"
      android:gravity="top"
      android:layout_height="@dimen/menu_bar_height"
      android:layout_width="fill_parent">
      <Button
          android:id="@+id/btn_home"
          android:text="@string/btn_home"
          android:drawableTop="@drawable/home_button"
          style="@style/MnuBtnStyle"
      />
...

there are other buttons and this layout is acting as a top menu bar that is included in whatever layout needs it.

The onClick event for the button is only fired on second click of the button due to the focusable lines.

        <item name="android:focusable">true</item>
        <item name="android:focusableInTouchMode">true</item>

The first click sets focus on the button then the second click fires the onClick event listener
I need to combine the two together so that the first click sets focus AND fires the onClick event listener. Can this be done?

If I remove the two focusable lines the buttons behave normally but I want to show that the button is focused and I want the scrolling text inside the button that <item name="android:ellipsize">marquee</item> gives me

Any ideas greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:02:52+00:00Added an answer on May 24, 2026 at 11:02 am

    You might need to use an OnFocusChangeListener and then check if the focus event happened when the screen was in touch mode: if it did then it was a user click, otherwise it was from the trackball/trackpad.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: Solution at bottom. I recently switched from using a set up such as
Update: Solved, with code I got it working, see my answer below for the
Update: giving a much more thorough example. The first two solutions offered were right
UPDATE: Focus your answers on hardware solutions please. What hardware/tools/add-in are you using to
[Update] Solved the Problem by generating a new web.config. Possible error was the second
Update: Originally, this post was using Books as the example entity, with Books1 ,
Update : Properly initialising string with char string[sizeof buffer - 1] has solved the
UPDATE TABLE1 set TABLE1.col1 = TABLE2.col1 FROM TABLE2 INNER JOIN TABLE3 ON COL2 =
UPDATE users u JOIN (select count(*) as job_count, user_id from job_responses where date_created >
UPDATE #2: I have solved almost all my issues bar the one major one.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.