小编Oli*_*ver的帖子

偏好活动中的Android更新语言

在我的Android应用程序中,我有一个偏好活动,让用户覆盖应用程序的语言.为了实现这一点,我在每个活动的onResume()中调用此函数,然后重置内容视图:

    public static void checkOverrideSystemLanguage(Context context) {
    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(context);

    // Check if system's language setting needs to be overridden
    boolean overrideSystemLanguage = prefs.getBoolean(context
            .getString(R.string.pref_key_chkbx_override_system_language),
            false);

    if (overrideSystemLanguage) {

        // Get language selection and possible languages
        String localeString = prefs.getString(
                context.getString(R.string.pref_key_list_languages), "");
        List<String> possibleLanguages = Arrays.asList(context
                .getResources().getStringArray(
                        R.array.pref_values_list_languages));

        if (possibleLanguages.contains(localeString)) {

            // Change language setting in configuration
            Locale locale = new Locale(localeString);
            Locale.setDefault(locale);
            Configuration config = new Configuration();
            config.locale = locale;
            context.getResources().updateConfiguration(config,
                    context.getResources().getDisplayMetrics());
        }
        // Use default language …
Run Code Online (Sandbox Code Playgroud)

configuration android reload preferenceactivity

6
推荐指数
1
解决办法
5754
查看次数

整个对话框的Android onTouchListener

我有一个对话框来选择文件.此对话框包含用于显示目录和文件的列表视图,并具有用于导航目的的onItemClickListener.

如何对目录结构中的fling事件做出反应?我尝试在根RelativeLayout上设置一个OnTouchListener来将触摸事件分派给我的GestureListener:

    final GestureDetector detector = new GestureDetector(new MyGestureDetector(tvCurrentPath));     
        dialog.findViewById(R.id.rlFilelist).setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View view, MotionEvent e) {
                detector.onTouchEvent(e);
                return false;
            }
        });
Run Code Online (Sandbox Code Playgroud)

事件在onTouch()中注册,但onFling()方法永远不会在MyGestureDetector中调用.但是,如果我将OnTouchListener附加到列表视图,它将按预期工作.这种方法的问题在于listview并不总是充满数据,当它是空的或点击下面的项目时,没有触发onTouch()事件.

对话框布局:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rlFilelist"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:focusable="true" >    

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/llButtons" >

        <TextView
            android:id="@+id/tvCurrentPath"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip" >
        </TextView>

        <ListView
            android:id="@+id/lvFileListing"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@id/llButtons"
            android:layout_below="@id/tvCurrentPath" >
        </ListView>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/llButtons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="5dip"
        android:layout_marginTop="5dip" >

        <Button
            android:id="@+id/btAddDirectory"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginRight="10px"
            android:text="@string/host_tv_dg_add_directory" />

        <Button
            android:id="@+id/btUp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10px" …
Run Code Online (Sandbox Code Playgroud)

android dialog gesture onfling gesturedetector

2
推荐指数
1
解决办法
6970
查看次数