2011-08-08 116 views
1

我想添加一个警告对话,点击按钮,但一些它如何不工作..但我添加的祝酒工作完美。请有人帮我解决。我在创建对象时直接添加了上下文而不是“this”[new AlertDialog.Builder(context).create();正如当我加入这个,这是给我的错误“的构造AlertDialog.Builder(新View.OnClickListener(){})是未定义”Android:alertDialog不工作

 public View getChildView(int groupPosition, int childPosition, boolean isLastChild, 
      View convertView, ViewGroup parent) { 
     Service service = (Service) getChild(groupPosition, childPosition); 
     if (convertView == null) { 
      LayoutInflater infalInflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.child_layout, null); 
     } 
     TextView tv = (TextView) convertView.findViewById(R.id.tvChild); 
     Drawable d = convertView.findViewById(R.id.submit).getBackground(); 
     PorterDuffColorFilter filter = new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP); 
     d.setColorFilter(filter); 
     tv.setText(" " + service.getName()); 
     this.submitButton = (Button)convertView.findViewById(R.id.submit); 
     this.submitButton.setText("Activate"); 
     this.submitButton.setOnClickListener(new OnClickListener() { 
       public void onClick(View v) { 
       Toast.makeText(context, "Service Activation Request Send", Toast.LENGTH_LONG).show(); 
       AlertDialog alertDialog = new AlertDialog.Builder(context).create(); 
       alertDialog.setTitle("Alert 1"); 
       alertDialog.setMessage("This is an alert"); 
       alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
        return; 
       } }); 
       } 
       }); 

     //this.submitButton.setPadding(20, 0, 0, 0); 

     // Depending upon the child type, set the imageTextView01 
     tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); 
     if (service instanceof DataService) { 
      tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.data, 0, 0, 0); 
     } else if (service instanceof VoiceService) { 
      tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.voice, 0, 0, 0); 
     } else if (service instanceof SmsService) { 
      tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.sms, 0, 0, 0); 
     } 
     return convertView; 
     } 

回答

3

调用show()方法上alertDialog

+0

哇调用的ShowDialog(INT)显示您的按钮onClickListener对话框。它帮助我..对不起,我在S illy问题 – Codemator

0

要调用()设置的任何字段,你也不会调用展()之前创建

Android的文档指出它能够更好地在我们的活动的onCreateDialog(int)的定义对话框创建回调方法

http://developer.android.com/guide/topics/ui/dialogs.html

你能做到这一点,然后通过与相关标识