构造函数Intent(new View.OnClickListener(){},Class <changepasswordactivity>)未定义</changepasswordactivity>

时间:2014-12-09 06:30:13

标签: java android

你有错误构造函数Intent(新的View.OnClickListener(){},Class)是未定义的,我在该类中创建了Util类,在该布局屏幕注销中创建弹出布局,如创建textview的chanage密码那个文本视图onClick我必须调用另一个活动。那个时候它显示了这个错误。

public class Util {


public static void initPopWindow(Activity a, Button button)
{
    final Context context = a;  
    // popupWindow
    View contentView = LayoutInflater.from(a).inflate(R.layout.my_list, null);
 // popupWindow
    contentView.setBackgroundColor(Color.LTGRAY);           
    popupWindow = new PopupWindow(contentView, 340, 249, true);
    contentView.setFocusableInTouchMode(true);      
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.showAtLocation(button, Gravity.TOP|Gravity.RIGHT, 2, 127);



 change_passwrod_activity.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub


            startActivity((new Intent(this, ChangePasswordActivity.class)));

        }
    });
}

}




main Activity call 
public void onSetting(View v) {
 Util.initPopWindow(this, menubutton)
 }

3 个答案:

答案 0 :(得分:0)

通常关键字指向当前类,此处您当前的类是 Util.java

Use activity **context** instead of **this**, because Intent need reference of activity class. It will not accept any other class reference

startActivity((new Intent(context, ChangePasswordActivity.class)));

答案 1 :(得分:0)

context.startActivity((new Intent(context, ChangePasswordActivity.class)));

答案 2 :(得分:0)

change_passwrod_activity.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        context.startActivity(new Intent(context, ChangePasswordActivity.class));
    }

});

startActivity()是Context中的一个方法,而不是OnClickListener或Util类中的方法。