2012-03-28 3 views
6

접근 가능한 앱을 개발 중입니다. 이를 위해 인터페이스의 모든 요소가 Talckback으로 읽을 수 있도록 포커스를 올바르게 얻을 수 있어야합니다. 이 질문에 Preference List only shows first elementListView에서 포커스가 예상대로 작동하지 않습니다.

그것은 터치 모드에서 완벽하게 작동처럼 나는, 내부 ListViewPreferenceActivity을 구축,하지만 난 활성화 Talckback와 ListView에 액세스하려고 할 때 (나는 ListView 집중 가려고 것입니다) , 그것은 내가 예상했던 것처럼 작동하지 않습니다. 나는 목록의 자식들이 초점을 가지기를 원한다. 전체 목록이 초점을 얻지는 않는다. 내 PreferenceActivity 내부


내가 추가 문제가

enter image description hereenter image description here

, 두 ListViews 스크롤을 가지고 있으며, 스크롤이 제대로 작동하지 않습니다. ListView을 스크롤 할 수 없게 할 수 있습니까?

감사

코드 :

ListPreferences.java (사용자의 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 (PreferenceActivity를의 XML)

<?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); 
    } 

} 
+0

이리스트 뷰에서리스트 뷰가 작동하지 않습니다. 내부리스트 뷰를 LinearLayout로 옮겨 놓습니다. – WarrenFaith

+0

'setFocusableInTouchMode (true)'를 사용하려고합니까? –

+0

LinearLayaout으로 시도해 보았지만 같은 결과를 얻었지만 더 나쁜 인터페이스를 사용하면 LinearLayout으로 포커스의 올바른 기능을 얻을 수 있다면 변경할 예정이지만 현재로서는 그렇지 않습니다. – Mun0n

답변

2
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(); 
} 

} 

고해상도/레이아웃/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> 

고해상도/값/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

아니면 그 라인을 따라 무언가가 작동합니다 –

+0

당신은 하나님입니다 ..... 나는 그렇게하려고합니다 ... 감사합니다! – Mun0n

+0

아참. 그것은 나에게 몇 가지 오류를 준다. 하나는 radioButton.setOnClickListener (this)에 있습니다. 내가 올바르게 구현하고 있다고 확신한다. ?? . 하지만 주요 오류는 내가 애플 리케이션을 실행하려고하면, 그것은 레이아웃의 팽창에 오류가 발생, 왜 모르겠어요. 레이아웃에 TextView를 만들 필요가 없습니다. RadioGroup을 보여 드리고 싶습니다. – Mun0n

관련 문제