0

I have created menu bar in second activity and there are multiple option items for different activities.

There are two options if i click on one option then it has to display images with contact details (like Name, Mobile no, Area) and also need to give an option to upload new images with contact details (like Name, Mobile no, Area). The same should be available for second option as well.

If i click on gallery then it has to display images and also it has to display camera option to upload new images. If i didn't like the image then i need an option to delete the image and click new image and then image has to upload in gallery with contact details(like Name, Mobile no, Area). And also i can upload images from my phone.

If i click on settings option it has to display all settings options for me.

If i click on logout option then logout should be successful and page must be redirect to Main Activity.

Please help me.

1 Answers1

0

On your Activity, you need to override these methods:

  @Override  
    public boolean onCreateOptionsMenu(Menu menu) {  
        // Inflate the menu; this adds items to the action bar if it is present.
        // inflate your menu file here  
        getMenuInflater().inflate(R.menu.menu_main, menu);  
        return true;  
    }  

    @Override  
    public boolean onOptionsItemSelected(MenuItem item) {  
       int id = item.getItemId();  
        switch (id){  
            case R.id.item1: 

                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Select 
                Picture"), 100); 

                return true;  
            case R.id.item2:  
                Intent photoCaptureIntent = new 
                Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(photoCaptureIntent, 101); 

                return true;  
            case R.id.item3:  
                Toast.makeText(getApplicationContext(),"Item 3 Selected",Toast.LENGTH_LONG).show();  
                return true;  
            default:  
                return super.onOptionsItemSelected(item);  
        }  
    } 

onActivityResult check the requestCode set image data to your imageView

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == RESULT_OK){
            switch (this.resultCode){
                 case 100:
                    Bitmap bitmap = (Bitmap)data.getExtras().get("data");
                    galleryImageView.setImageBitmap(bitmap);
                    break;

                case 101:
                    Bitmap bitmap = (Bitmap)data.getExtras().get("data");
                    capturedImageView.setImageBitmap(bitmap);
                    break;

               default:
                  break;
            }

        }
    }

Inside onOptionsItemSelected(MenuItem item) check your menu_item_id like this and open your Activity which you want open on these items click.

Krishna Sony
  • 1,286
  • 13
  • 27
  • I have done this. I want to add images from gallery or through camera click and also with contact details(like Name, Mobile no, Area) in item 1, item 2, and item 3. If i click on settings option then it has to display settings like in our we have settings about device, themes etc., i need same settings option in my app. I also want logout code if user clicks on logout then page must be redirect to main activity in android studio – Nomula Bhavanishankar May 22 '20 at 13:47
  • check this code this will help you to handle capture image from camera https://stackoverflow.com/a/61956468/9523118 – Krishna Sony May 22 '20 at 13:50
  • In activity result setImageView is displaying error and i'm unable to resolve it – Nomula Bhavanishankar May 22 '20 at 14:45
  • then search accordingly there is lots of solution search on StackOverflow you will find it . Check this https://stackoverflow.com/a/19806967/9523118 – Krishna Sony May 22 '20 at 16:42
  • If I answered your all question then accept my answer, if you want to. – Krishna Sony May 22 '20 at 16:42