我有5个标签的Tab Activity,即相机,图库,列表,历史记录和相机标签中的注销我打开相机并拍照并保存在图库中,同时我用这个选中的图像打开表格。我的问题是,当我没有填写表单并移动到其他选项卡并再次返回到该相机时,它显示在onActivityResult()函数中使用的相同布局是我的代码。请给我答案,我们可以完成活动开放onActivityResult()。
public class PhotoScreen extends Activity{
//private static final String[] COUNTRIES = new String[] {"Apartment", "Land"};
public int TAKE_PICTURE = 0;
Button takepicture;
public static String propertynamevalue;
Bitmap mBitmap = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photolayout);
takepicture = (Button) findViewById(R.id.button1);
takepicture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data)
{
setContentView(R.layout.publish);
super.onActivityResult(requestCode, resultCode, data);
final DatabaseHandler db=new DatabaseHandler(this.getBaseContext());
Button save =(Button)findViewById(R.id.save);
if (requestCode == TAKE_PICTURE)
{
if(resultCode == RESULT_OK)
{
Log.v("test", "Camera intent succeeded");
mBitmap = (Bitmap) data.getExtras().get("data");
ImageView imageView =(ImageView)findViewById(R.id.imgView);
Canvas can = new Canvas();
can.setBitmap(Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.RGB_565));
imageView.setImageBitmap(mBitmap);
}
else if(resultCode == RESULT_CANCELED)
{
setContentView(R.layout.photolayout);
Log.i("test1", "Camera intent aborted");
}
else
{
Log.e("test2", "Camera intent failed with result code: " + resultCode);
}
}
save.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// Inserting Property
EditText propname=(EditText)findViewById(R.id.etcity1);
EditText propcost=(EditText)findViewById(R.id.etcity2);
EditText propaddress=(EditText)findViewById(R.id.etcity3);
EditText propbuilduparea=(EditText)findViewById(R.id.etcity4);
EditText propcategory=(EditText)findViewById(R.id.etcity5);
Log.d("Insert: ", "Inserting ..");
db.addProperty(new Property(propname.getText().toString(), propcost.getText().toString(),propaddress.getText().toString(),propbuilduparea.getText().toString(),propcategory.getText().toString()));
//Log.d("propcost: ", ""+Double.parseDouble(propcost.getText().toString())+"");
propname.setText("");
propcost.setText("");
propaddress.setText("");
propbuilduparea.setText("");
propcategory.setText("");
// Reading all contacts
List<Property> property = db.getAllContacts();
for (Property cn : property){
Log.d("Reading: ", "Reading all contacts..");
String log = "Id: "+cn.getID()+" ,Name: " + cn.getName() + " ,Cost: " + cn.getCost()+ " ,Address: " + cn.getAddress()+ " ,Builduparea: " + cn.getBuilduparea()+" ,Category: " + cn.getCategory();
// Writing Contacts to log
Log.d("Name: ", log);
}
setContentView(R.layout.photolayout);
Toast.makeText(getApplicationContext(), "Your Data Has been saved successfully", Toast.LENGTH_LONG).show();
}
});
}