0

我有带有 5 个选项卡的选项卡活动,即相机选项卡中的相机、画廊、列表、历史记录和注销我打开相机并拍照并保存在画廊中,同时我用这个挑选的图像打开表单。我的问题是当我不填写表格并移动到其他选项卡并再次回到该相机时,它显示 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();
            }



    });

}
4

0 回答 0