我已编写此代码,但此代码在警告对话框中显示错误。错误是未定义的构造函数。
public class Age extends Fragment implements OnClickListener{
public Age(){}
TableRow tr1,tr2,tr3,tr4,tr5,tr6,tr7,tr8,tr9,tr10,tr11;
AlertDialog builder;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout. activity_age, container, false);
builder = new AlertDialog.Builder(Age.this, AlertDialog.THEME_HOLO_LIGHT).create();
tr2=(TableRow)rootView.findViewById(R.id.tableRow2);
tr3=(TableRow)rootView.findViewById(R.id.tableRow3);
tr2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
builder.setIcon(R.drawable.mercury);
builder.setTitle("About Mercury"); builder.setInverseBackgroundForced(true);
builder.setMessage("Orbit: 57,910,000 km (0.38 AU) from Sun\ndiameter: 4,880 km\nmass: 3.30e23 kg\nGravity : 0.378");
builder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {}});builder.show();}});
}
}
答案 0 :(得分:1)
替换此行
builder = new AlertDialog.Builder(Age.this, AlertDialog.THEME_HOLO_LIGHT).create();
与
builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_LIGHT).create();