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 7725885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:03:55+00:00 2026-06-01T05:03:55+00:00

I am developing an accessible app. For this purpose it is important that all

  • 0

I am developing an accessible app. For this purpose it is important that all elements of the interface can obtain the focus correctly, so that they can be read by Talckback.
I build a PreferenceActivity with a ListView inside, like in this question Preference List only shows first element

It works perfect in touch mode, but when I try to access to the ListView with the Talckback activated (It’s like I try to get Focused the ListView), It doesn’t work like I expected. I want the children of the list get the focus, not the entire list gets the focus.

enter image description hereenter image description here

I have an additional problem, the two ListViews inside my PreferenceActivity has scroll, and the scroll is not working right. Can I make the ListView no scrollable?

Thanks

Code:

ListPreferences.java (Custom ListView)

import com.battleship.R;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.Preference;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.OnHierarchyChangeListener;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;

public class ListPreferences extends Preference implements
        OnCheckedChangeListener, OnHierarchyChangeListener {

    private ListView listView;
    private View thisView;
    private int listHeight = 0;

    public ListPreferences(Context context) {
        super(context);
    }

    public ListPreferences(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ListPreferences(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onClick() {

        super.onClick();
        Toast t = Toast.makeText(getContext(), "HOLA!", 3);
        t.show();
    }

    @Override
    protected View onCreateView(ViewGroup parent) {

        this.setLayoutResource(R.layout.listview_preference_layout);
        thisView = super.onCreateView(parent);
        listView = (ListView) thisView.findViewById(android.R.id.list);
        listView.setOnHierarchyChangeListener(this);

        String[] contentString = new String[3];
        if (getKey().equals("theme")) {
            contentString = new String[] {
                    (getContext().getString(R.string.settings_theme_default)),
                    (getContext().getString(R.string.settings_theme_black)),
                    (getContext().getString(R.string.settings_theme_white)) };
        } else {
            contentString = new String[] {
                    (getContext().getString(R.string.settings_font_big)),
                    (getContext().getString(R.string.settings_font_medium)),
                    (getContext().getString(R.string.settings_font_little)) };
        }

        ArrayAdapter<String> array = new ArrayAdapter<String>(getContext(),
                android.R.layout.simple_list_item_single_choice,
                android.R.id.text1, contentString);
            listView.setAdapter(array);
            listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            listView.setFocusable(false);
            listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
            return thisView;    

    }





    private void updatePreference(int intRadio) {
        SharedPreferences.Editor editor = getEditor();
        editor.putInt(getKey(), intRadio);
        editor.commit();
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        updatePreference(checkedId);
        notifyChanged();
    }

    @Override
    public void onChildViewAdded(View parent, View child) {
        int childHeight = child.getMeasuredHeight();
        if(childHeight > 0)
        {
            listHeight = listView.getAdapter().getCount() * childHeight;
            thisView.setMinimumHeight(listHeight);
            Log.i("LISTA","onChildViewAdded, done: "+listHeight+" "+childHeight);
        }
    }

    public void onChildViewRemoved(View parent, View child) {
    }

}

preference.xml (xml of PreferenceActivity)

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <PreferenceCategory
        android:key="player_settings"
        android:title="@string/settings_player_config" >
        <EditTextPreference
            android:defaultValue="@string/settings_player_default_name"
            android:dialogMessage="@string/settings_player_summary"
            android:dialogTitle="@string/settings_playersname"
            android:key="player_name"
            android:summary="@string/settings_player_summary"
            android:title="@string/settings_playersname" />
    </PreferenceCategory>
    <PreferenceCategory
        android:key="volume"
        android:title="@string/settings_volume" >
        <com.battleship.preferences.SeekBarPreferences
            android:defaultValue="50"
            android:key="volume"
            android:title="@string/settings_volume" />
    </PreferenceCategory>
    <PreferenceCategory
        android:key="shine"
        android:title="@string/settings_shine" >
        <com.battleship.preferences.SeekBarPreferences
            android:defaultValue="50"
            android:key="shine"
            android:title="@string/settings_shine" />
    </PreferenceCategory>
    <PreferenceCategory
        android:key="themeTitle"
        android:title="@string/settings_group_themes" >
        <com.battleship.preferences.ListPreferences android:key="theme" />
    </PreferenceCategory>
    <PreferenceCategory
        android:key="fontsTitle"
        android:title="@string/settings_group_font_size" >
        <com.battleship.preferences.ListPreferences android:key="font" />
    </PreferenceCategory>

</PreferenceScreen>

SettingsActivity.java (PreferenceActivity)

package com.battleship;
import com.battleship.R;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class SettingsActivity extends PreferenceActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }
    @Override
    public View getCurrentFocus() {
        Log.d("FOCO", "" + super.getCurrentFocus());
        return super.getCurrentFocus();
    }
    @Override
    public boolean onTrackballEvent(MotionEvent event) {
        Log.d("TRACKBALL", "" + event);
        return super.onTrackballEvent(event);
    }

}
  • 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-06-01T05:03:56+00:00Added an answer on June 1, 2026 at 5:03 am
    import com.battleship.R;
    
    import android.content.Context;
    import android.content.SharedPreferences;
    import android.preference.Preference;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.ViewGroup.OnHierarchyChangeListener;
    import android.widget.ArrayAdapter;
    import android.widget.LinearLayout;
    import android.widget.RadioButton;
    import android.widget.RadioGroup;
    import android.widget.RadioGroup.OnCheckedChangeListener;
    import android.widget.Toast;
    
    public class ListPreferences extends PreferenceCategory implements OnPreferenceClickListener, OnPreferenceChangeListener{
    
    private final String TAG = getClass().getSimpleName();
    private final Context mContext;
    private PreferenceScreen parentScreen;
    private View thisView;
    
    public FilterPreferenceCategory(Context context) {
        super(context);
        mContext = context;
    }
    
    public FilterPreferenceCategory(Context context, PreferenceScreen preferenceScreen) {
        super(context);
        mContext = context;
        parentScreen = preferenceScreen;
    }
    
    @Override
    protected View onCreateView(ViewGroup parent) {
        this.setLayoutResource(R.layout.rb_group_layout);
        Log.i(TAG, "onCreateView");
        if(thisView == null)
        {
            thisView = super.onCreateView(parent);
            RadioGroup radioGroup = (RadioGroup) thisView.findViewById(R.id.radioGroup);
            final String[] contentString = getKey().equals("theme") ? mContext.getResources().getStringArray(R.array.theme_stuff) : mContext.getResources().getStringArray(R.array.font_stuff);
            int i;
            for(i = 0; i < contentString.length; i++)
            {
                    RadioButton radioButton = new RadioButton(mContext);
                    radioButton.layout(0, 0, 0, 0);
                    radioButton.setFocusable(true);
                    radioButton.setFocusableInTouchMode(true);
                    radioButton.setOnClickListener(this);
                    radioButton.setText(contentString[i]);
                    radioGroup.addView(radioButton);
            }
        }
        return thisView;
    }
    
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        Log.i(TAG, "onPreferenceChange");
        return false;
    }
    
    public boolean onPreferenceClick(Preference preference) {
        Log.i(TAG,"onPreferenceClick");
        return false;
    }
    
    @Override
    protected void onAttachedToActivity() {
        Log.i(TAG,"onAttachedToActivity");
        super.onAttachedToActivity();
    }
    
    public void onClick(View v) {
        v.requestFocus();
        v.requestFocusFromTouch();
    }
    
     }
    

    res/layout/rb_group_layout.xml:

    <?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:orientation="vertical"
        android:padding="10dp"
        android:background="#000000"
        android:weightSum="2"
         >
        <LinearLayout
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_gravity="top"
            android:orientation="vertical"
            android:gravity="center"
            android:paddingRight="10dp" >
            <TextView
                android:id="@android:id/summary"
                style="@android:style/TextAppearance.Medium"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:paddingBottom="5dp"
                />
            <TextView 
                android:id="@android:id/summary"
                style="@android:style/TextAppearance.Small"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical" />
        </LinearLayout>
        <RadioGroup
            android:id="@+id/radioGroup"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
             >
        </RadioGroup>
    </LinearLayout>
    

    res/values/arrays.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string-array name="theme_stuff">
            <item>@string/settings_theme_default</item>
            <item>@string/settings_theme_black</item>
            <item>@string/settings_theme_white</item>
        </string-array>
        <string-array name="font_stuff">
            <item>@string/settings_font_big</item>
            <item>@string/settings_font_medium</item>
            <item>@string/settings_font_little</item>
        </string-array>
    </resources>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an app that will require setting and removing alarms accordingly. I'm wondering
We're looking into developing an application that can read from and write to Lotus
If I am developing an app that has a 30 day trial, for example,
I am developing an Android App that gets some data from a web server,
I am developing a WPF/Entity Framework 4 app that uses SQL Compact 4.0 as
We are developing a web application that should be accessible from a mobile phone.
I am developing an iPad app for some clients. This app is like a
Developing a .NET WinForms application: how can I check if the window is in
I'm developing an iOS5 App using ARC, and I started to get some random
I'm developing a CAC authentication app. I'm running RHEL 5.5 and have a card

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.