Android 构造函数AlertDialog.Builder(LayoutOne,int)未定义
我是编程新手,在工作中遇到一些困难。我有六个按钮显示,我想添加警报对话框时,第六个按钮被单击。但是我得到一个错误,说构造函数AlertDialog.BuilderLayoutOne,int未定义。有人能帮我吗 谢谢大家!Android 构造函数AlertDialog.Builder(LayoutOne,int)未定义,android,android-alertdialog,Android,Android Alertdialog,我是编程新手,在工作中遇到一些困难。我有六个按钮显示,我想添加警报对话框时,第六个按钮被单击。但是我得到一个错误,说构造函数AlertDialog.BuilderLayoutOne,int未定义。有人能帮我吗 谢谢大家! public class LayoutOne extends Fragment implements OnClickListener { public static Fragment newInstance(Context context) { Lay
public class LayoutOne extends Fragment implements OnClickListener {
public static Fragment newInstance(Context context) {
LayoutOne f = new LayoutOne();
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater
.inflate(R.layout.layout_one, null);
((Button) root.findViewById(R.id.drink)).setOnClickListener(this);
((Button) root.findViewById(R.id.sleep)).setOnClickListener(this);
((Button) root.findViewById(R.id.food)).setOnClickListener(this);
((Button) root.findViewById(R.id.events)).setOnClickListener(this);
((Button) root.findViewById(R.id.beach)).setOnClickListener(this);
((Button) root.findViewById(R.id.map)).setOnClickListener(this);
return root;
}
public void onClick(View v) {
// TODO Auto-generated method stub
Button tmp = (Button) v;
Button map = (Button) v;
if (tmp.getId() == R.id.drink) {
startActivity(new Intent("com.creatriks.zrce.DRINK"));
}
if (tmp.getId() == R.id.sleep) {
startActivity(new Intent("com.creatriks.zrce.SLEEP"));
}
if (tmp.getId() == R.id.food) {
startActivity(new Intent("com.creatriks.zrce.FOOD"));
}
if (tmp.getId() == R.id.events) {
startActivity(new Intent("com.creatriks.zrce.EVENTS"));
}
if (tmp.getId() == R.id.beach) {
startActivity(new Intent("com.creatriks.zrce.BEACH"));
}
if (map.getId() == R.id.map) {
AlertDialog alert = new AlertDialog.Builder(LayoutOne.this, AlertDialog.THEME_HOLO_LIGHT).create();
alert.setTitle("Options");
alert.setMessage("Choose an action");
startActivity(new Intent("com.creatriks.zrce.MAP"));
}
}
}使用getActivity返回与片段关联的活动
改变这个
AlertDialog alert = new AlertDialog.Builder(LayoutOne.this, AlertDialog.THEME_HOLO_LIGHT).create();
对此
AlertDialog alert = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_LIGHT).create();
使用getActivity返回与片段关联的活动
改变这个
AlertDialog alert = new AlertDialog.Builder(LayoutOne.this, AlertDialog.THEME_HOLO_LIGHT).create();
对此
AlertDialog alert = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_LIGHT).create();
这没关系。问题是构造函数AlertDialog.BuilderLayoutOne,int未定义这无关紧要。问题在于构造函数AlertDialog.BuilderLayoutOne,int未定义