Como nesse trecho:
@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);
}
}
}
}
Existe alguma maneira de utilizar o mesmo esquema de tirar fotos através dos imageButton, utilizando dois layouts, com a mesma Activity?
Infelizmente, a sintaxe "setContentView();" autoriza apenas uma por vez.
PS.: Estou utilizando o Eclipse do ADT Bundle para desenvolvimento em Android.
EDIT.: Seguem abaixo os dois .xml relativos às telas:
Adicionar contato:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/addFirstName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="103dip"
android:inputType="text"
android:hint="First name" >
</EditText>
<EditText
android:id="@+id/addLastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/addFirstName"
android:layout_marginLeft="103dip"
android:inputType="text"
android:hint="Last name"
android:width="190dip" >
</EditText>
<EditText
android:id="@+id/addPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/addLastName"
android:layout_marginLeft="103dip"
android:layout_toRightOf="@+id/txtAux5"
android:inputType="text"
android:hint="Phone number"
android:width="190dip" >
</EditText>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/addPhone"
android:gravity="center_vertical" >
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_weight="1.0"
android:onClick="btnSave_click"
android:text="Save">
</Button>
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/addPhone"
android:layout_weight="1.0"
android:text="Cancel" >
</Button>
</LinearLayout>
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="103dip"
android:layout_height="103dip"
android:layout_above="@+id/linearLayout1"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/addFirstName"
android:src="@drawable/avatar" />
</RelativeLayout>
Editar contato:
<EditText
android:id="@+id/edtFirstName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="103dip"
android:inputType="text"
android:hint="First name" >
</EditText>
<EditText
android:id="@+id/edtLastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/edtFirstName"
android:layout_marginLeft="103dip"
android:inputType="text"
android:hint="Last name"
android:width="190dip" >
</EditText>
<EditText
android:id="@+id/edtPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/edtLastName"
android:layout_marginLeft="103dip"
android:layout_toRightOf="@+id/txtAux5"
android:inputType="text"
android:hint="Phone number"
android:width="190dip" >
</EditText>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/edtPhone"
android:gravity="center_vertical" >
<Button
android:id="@+id/btnConfirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_weight="1.0"
android:onClick="btnConfirm_click"
android:text="Confirm">
</Button>
<Button
android:src="@drawable/delete"
android:id="@+id/btnDelete"
android:text=" Delete "
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</Button>
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/edtPhone"
android:layout_weight="1.0"
android:text="Cancel" >
</Button>
</LinearLayout>
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="103dip"
android:layout_height="103dip"
android:layout_above="@+id/linearLayout1"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/edtFirstName"
android:src="@drawable/avatar" />