小编Kou*_*dar的帖子

Android:在开关上使用setOnCheckedChangeListener时,我得到'无法解决符号错误'

package com.example.koustav.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class MainActivity extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    Switch swi = (Switch) findViewById(R.id.swch);
    swi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
    {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) //Line A
        {

        }
    });

    public void onClick(View view)
    {
        boolean isOn = ((Switch) view).isChecked();

        if (isOn)
        {
            ((TextView) findViewById(R.id.largey)).setTextColor(getResources().getColor(R.color.black));
        }
        else
        {
            ((TextView) findViewById(R.id.largey)).setTextColor(getResources().getColor(R.color.white));
        }

    }

}
Run Code Online (Sandbox Code Playgroud)

我在这个项目中使用Android Studio.我已经在互联网上搜索了一个可扩展的解决方案但找不到解决方案.

我一直试图setOnCheckedChangeListener用于一个Switch对象.但无论我尝试什么,我总是得到一个 …

android compiler-errors oncheckedchanged android-studio

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