@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.addcontact);
imageButton01 = (ImageButton) findViewById(R.id.imageButton1);
imageButton01.setOnClickListener(this);
@Override
public void onClick(View view)
{
if (view == imageButton01)
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PHOTO);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == TAKE_PHOTO)
{
if (resultCode == RESULT_OK)
{
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
imageButton01.setImageBitmap(bitmap);
}
else if (resultCode == RESULT_CANCELED)
{
Toast.makeText(this, "Canceled", Toast.LENGTH_SHORT);
}
else
{
Toast.makeText(this, "Left", Toast.LENGTH_SHORT);
}
}
}
}
是否可以复制“setContentView();”,“findViewById();”和其他方法,或类似的东西?我想使用相同的代码在单击图像按钮时使用相机,但使用不同的布局会使用相同的代码。