我正在努力解决一个宣布抽象实施的抽象"错误。我在单击自定义布局中的按钮时实现回调接口捕获数据的过程中,我收到此错误。我在我的活动中调用了覆盖方法(TestDialogInterface),但这似乎无法解决问题。以下是尝试解决特定问题时的具体信息。
错误: " Class' TestActivity'必须被声明为抽象或实现抽象方法&on; onPositiveClick(int)'在&InterfaceHistener'"
中TextActivity类:
public class TestActivity implements TestDialogInterface.InterfaceListener {
@Override
public void onClickPositive(int someNumber){
//do something
}
...
}
TestDiaologInerface.java:
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
public class TestDialogInterface extends DialogFragment {
public interface InterfaceListener {
public void onPositiveClick(int someNumber);
}
InterfaceListener interfaceListener;
//check to see if interface is utilized in main activity event
@Override
public void onAttach(Context context){
super.onAttach(context);
try {
interfaceListener = (InterfaceListener) context;
} catch (ClassCastException e){
throw new ClassCastException(context.toString() + " must implement InterfaceListner");
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Select Date")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
interfaceListener.onPositiveClick(1);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
return builder.create();
}
}