android context参数 this 调用方法——菜瓜笔记

编写了一个类,该类的构造函数参数包含了context,在调用过程中输入this总是报错,一时间不知所措,按照eclipse的提示修改又不能得到正确结果,经过查阅资料终于知道具体的调用方法。

类中定义的构造函数为:

public TakeMediaDialog(Context paramContext, String paramString, TakeMediaDialogType paramTakeMediaDialogType, TakeMediaDialogListener onClickListener)
{
	super(paramContext, R.style.LivestreamDialogsTheme);
	this.activity = ((Activity)paramContext);
	this.title = paramString;
	this.type = paramTakeMediaDialogType;
	this.listener = paramTakeMediaDialogListener;
	    
}


在另外一个类中调用该类

public class Signup extends Activity implements TakeMediaDialog.TakeMediaDialogListener
{

	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		
		setContentView(R.layout.ac_signup);
		
		ImageView imgView=(ImageView)findViewById(R.id.ac_signup_addphoto_icon);
		
		imgView.setOnClickListener(new View.OnClickListener()
		{
			
			private TakeMediaDialog takeMediaDialog;

			@Override
			public void onClick(View v)
			{
				
				// TODO Auto-generated method stub
				this.takeMediaDialog=new TakeMediaDialog(Signup.this, getString(R.string.ac_signup_dialog_set_picture), TakeMediaDialog.TakeMediaDialogType.IMAGE, Signup.this);
 				this.takeMediaDialog.show();
						
			}
		});
		
	}

	@Override
	public void onImageRemoved()
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onVideoRemoved()
	{
		// TODO Auto-generated method stub
		
	}

}


红色部分为正确的调用方法,使用调用类名称.this就可以了。  ClassName.this ,非常菜,记录以供其他童鞋查阅。

你可能感兴趣的:(编程)