获取错误必须实现继承的抽象方法

时间:2011-08-06 07:48:11

标签: java android

我是Android的新手并且正在获取类型LinearLayoutActivity必须实现继承的抽象方法RadioGroup.OnCheckedChangeListener.onCheckedChanged(RadioGroup,int)以获取错误。我不明白我是如何使RadioGroup成为一种抽象方法的。这是我的代码,我离开了//我在哪里得到错误

package com.commonsware.android.linear;

import com.commonsplace.android.skeleton.R;
import com.commonsplace.android.skeleton.R.id;
import com.commonsplace.android.skeleton.R.layout;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RadioGroup;
import android.widget.EditText;
import android.view.Gravity;
import android.text.TextWatcher;

public class LinearLayoutActivity extends Activity  //I am getting the error for    LinearLayoutActivity
 implements RadioGroup.OnCheckedChangeListener{
RadioGroup orientation;
RadioGroup gravity;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    orientation=(RadioGroup)findViewById(R.id.orientation);
    orientation.setOnCheckedChangeListener(this);
    gravity=(RadioGroup)findViewById(R.id.gravity);
    gravity.setOnCheckedChangeListener(this);
}

public void OnCheckedChanged(RadioGroup group, int checkedId){
    switch(checkedId){
    case R.id.horizontal:
    orientation.setOrientation(LinearLayout.HORIZONTAL);
    break;
    case R.id.vertical:
    orientation.setOrientation(LinearLayout.VERTICAL);
    break;
    case R.id.left:
    orientation.setGravity(Gravity.LEFT);
    break;
    case R.id.center:
    orientation.setGravity(Gravity.CENTER);
    break;
    case R.id.right:
        orientation.setGravity(Gravity.RIGHT);
    break;
    }

}

}

2 个答案:

答案 0 :(得分:4)

代码中方法的名称是错误的。你有:

public void OnCheckedChanged(RadioGroup group, int checkedId)

你需要:

public void onCheckedChanged(RadioGroup group, int checkedId)
            ^

Java区分大小写。

答案 1 :(得分:3)

你对函数OnCheckedChanged的名称犯了一点错误。实际上,它是onCheckedChanged,开头有一点“o”