0

这是我的代码,你能告诉我什么问题吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_bf"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:orientation="vertical" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="40dp"
                android:gravity="center_vertical"
                android:padding="10dp"
                android:text="SELECT YOUR LANGUAGES"
                android:textColor="#8E8D8D"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/langDutch"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/bg_settings_dutchon_hc_2x"
                android:drawablePadding="10dp"
                android:gravity="center_vertical"
                android:onClick="onlanguageSelect"
                android:padding="10dp"
                android:text="Dutch"
                android:textColor="#454C52" />

            <TextView
                android:id="@+id/langFlemish"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/bg_settings_dutchact_hc_2x"
                android:drawablePadding="10dp"
                android:gravity="center_vertical"
                android:onClick="onlanguageSelect"
                android:padding="10dp"
                android:text="Flemish"
                android:textColor="#454C52" />

            <TextView
                android:id="@+id/langFrench"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:drawableLeft="@drawable/bg_settings_franceon_hc_2x"
                android:drawablePadding="10dp"
                android:gravity="center_vertical"
                android:onClick="onlanguageSelect"
                android:padding="10dp"
                android:text="French"
                android:textColor="#454C52" />
        </LinearLayout>
    </ScrollView>

    <TextView
        android:id="@+id/settingscontinue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_margin="20dp"
        android:background="@drawable/button_hc_bf_language_2x"
        android:gravity="center"
        android:text="CONTINUE"
        android:textColor="@color/white"
        android:textSize="16sp"
        android:textStyle="bold" />

</LinearLayout>

这是在活动中:

public void onlanguageSelect(View v){
        Log.v("Language Settings: ", " onlanguageSelect clicked.");
        int id = v.getId();
        String lang;
        switch (id) {
        case R.id.langDutch:
            lang = "nl_NL";
            break;
        case R.id.langFlemish:
            lang = "nl_BE";
            break;
        case R.id.langFrench:
            lang = "fr";
            break;
        default:
            lang = "nl";
            break;
        }
        changeLocale(lang);
    }

    private void changeLocale(String localeString){
        Locale locale = new Locale(localeString);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
        Log.v("Language Settings: ", "language changed successfully.");
    }
4

2 回答 2

1

正如 Raghunandan 所说,每个 View 都必须标记为可点击才能使 onClick 处理程序工作。

为您的 TextViews 试试这个:

        <TextView
            android:id="@+id/langFrench"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/bg_settings_franceon_hc_2x"
            android:drawablePadding="10dp"
            android:gravity="center_vertical"
            android:onClick="onlanguageSelect"

            android:clickable="true"

            android:padding="10dp"
            android:text="French"
            android:textColor="#454C52" />
于 2013-08-07T12:31:45.297 回答
0

确保你已经在你的活动类中实现了 onClickListner() 接口。并确保您已在onCreate()方法中使用此类接口注册所有 TextView。

TextView btnDutch = (TextView ) findViewById(R.id.langDutch);
btnDutch.setOnClickListener(this);

这应该有效。

于 2013-08-07T12:28:39.573 回答