繁体   English   中英

构造函数Intent(new View.OnClickListener(){},类 <ChangePasswordActivity> )未定义

[英]The constructor Intent(new View.OnClickListener(){}, Class<ChangePasswordActivity>) is undefined

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

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)
 }

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

Use activity **context** instead of **this**, because Intent need reference of activity class. It will not accept any other class reference 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)));
context.startActivity((new Intent(context, ChangePasswordActivity.class)));
change_passwrod_activity.setOnClickListener(new OnClickListener() {

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

});

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM