兔子--The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined
2014-11-30 15:02
411 查看
出错原因:Builder builder=new Builder(this) 该方法里面的this为当前类OnClickListener的实例,
而不是我们想要赋值的MainActivity.this,只需要把this改为MainActivity.this。
我的代码如下:
而不是我们想要赋值的MainActivity.this,只需要把this改为MainActivity.this。
我的代码如下:
<span style="font-size:18px;">public class MainActivity extends Activity { private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn = (Button) findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub new AlertDialog.Builder(MainActivity.this) .setTitle("添加好友") .setMessage("请输入要添加好友的帐户:") .setIcon(android.R.drawable.ic_dialog_info) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // EChatAccountManager.getInstance() // .addContact( // new String[] { etAccount.getText() // .toString() }, "我要加你好有"); } }).setNegativeButton("取消", null).show(); } }); } </span>
相关文章推荐
- the constructor AlertDialog.Builder(new View.OnClickListener() ) is undefined
- 关于解决:the constructor AlertDialog.Builder(new View.OnClickListener() ) is undefined
- The constructor Intent(new View.OnClickListener(){}, Class<ButtonStudyActivity>) is undefined
- The constructor Intent(new View.OnClickListener(){}, Class<ButtonStudyActivity>) is undefined
- The constructor WeiboAuth(new View.OnClickListener(){}, String, String, String) is undefined
- The constructor Intent(new View.OnClickListener(){}, Class<ButtonStudyActivity>) is undefined
- 关于“The constructor ArrayAdapter(new View.OnClickListener(){}, int, String[]) is undefined”错误提示的解决办法
- The constructor SimpleAdapter(new View.OnClickListener(){},...)is undefined的问题及解决
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i
- Android listView,自定义Adapter,另The constructor AlertDialog.Builder(MyAdapter) is undefined问题
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i
- The constructor SimpleAdapter(new View.OnClickListener(){}, List<Map<String,Object>>, ..的解决方法
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder is not applicable for the arguments
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i
- Android 错误 The method onClick(View) of type new View.OnClickListener(){} must override a superclas
- The method onClick(View) of type new View.OnClickListener(){} must override a superclass