getting an error for must implement the inherited abstract method
I am new to android and am getting The type LinearLayoutActivity must implement the inherited abstract method RadioGroup.OnC开发者_Go百科heckedChangeListener.onCheckedChanged(RadioGroup, int) for an error. I don't understand how I made RadioGroup an abstract method. Here is my code, I left a // by where I am getting the error
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;
}
}
}
The name of the method in your code is wrong. You have:
public void OnCheckedChanged(RadioGroup group, int checkedId)
You need:
public void onCheckedChanged(RadioGroup group, int checkedId)
^
Java is case sensitive.
You have done a little mistake on the name of the function OnCheckedChanged
. In reality, it is onCheckedChanged
, with a little "o" at the beginning.
精彩评论