Android - OnClick open Image? - android-studio

I'm new in Android programming and I need a help!!!
I hava button on a middle on screen and I want to open an image when button is clicked. Image

I believe you would need to go to another activity assuming that your image viewer is on another activity.
Intent intent = new Intent(Main.this, Image.class);
startActivity(intent);
With main being the activity your on and image being the one with the image viewer.

Related

Adding Image button after Add button is clicked (Android Studio Java)

Is it possible in Android studio to produce an Image Button after I clicked a button like Add Button. If yes, how? I want to make an attendance app wherein if the user clicks Add Class an image button will appear
We have no idea of which layout of you are using as the parent. But, for the best results of my answer, linear layout is advised.
The thing you are trying to achieve is trying to create dynamic elements.
For this, you can create an instance of the ImageButton class and then add it to you layout. This can be dont as follows:
//inside onclick of the add button
ImageButton newView = new ImageButton(context);
parentView.addView(newView);
You can add customisations to the view before adding it to the view.

Switch from fragment to activity in android studio

I made an application where I integrated the tabbed activity. In the tabbed activity I put 3 fragments. Now in the 3rd fragment I put a button and I want when I click on the button it redirects me to a new activity I did. I used an intent as we usually do between activities but it doesn't work. Need help please
use getContext instade of Activity.this. use the below code in your button to redirect from fragment to activity
yourButton.setOnClickListener(view -> {
startActivity(new Intent(getContext(), Your_Activity.class));
});
If the problem is not solved yet, let me know with logcat error.

How To share Images in Android Studio

I have Added the image in drawable folder and then I displayed it on layout file and also added a button and after for it i have added on click method, now I want to share images to whatsapps and fb so how can I send it... Please help me....
It's very difficult to understand what you want, because of the missing code. But I will try to help you.
I found this solution:
public void shareImage() {
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
final File photoFile = new File(getFilesDir(), "image.jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
startActivity(Intent.createChooser(shareIntent, "Share image using"));
}
Just add shareImage() to the OnClickListener of your ImageView.
If you want more details check this, where I got the code from.
If you don't want to send an image from your gallery, then replace photoFile with the file wich you want to send.

How to pass video from 1st activity to 2nd activity when a button clicked? - android studio

In Activity1 I've a Button and videoView. When the button is clicked Activity2 is started.
In Activity2 I've a videoview2.
I want to display the video retrieved from videoView in Activity1 going to the videoview2 in Activity2 .
can someone help me with the code to make this work?
You must get the video file retrieved in a String or Uri. Make that object static, by putting the word static. You can then access the the static object by Activity1.object_name in the 2nd activity.

how to remove default graphic assigned to a control (like buttons and checkboxes) before setting new graphic to that control in java fx scene builder?

i am making a java desktop application using javafx. For gui building i am using scene builder 2.0.
Everything is just perfect as expected just 1 thing. I want to customize the buttons. i want to assign a custom graphic to a button.
When i use [button.setgraphic(node)] , this statement set the new graphic to the button but default graphic of button also remains present as well.
I just want to remove the default graphic and then want to assign the new (custom) garaphic to a control like buttons and radio buttons in javafx. 1 thing again i must tell that i am using scene builder for building gui.
How can i achieve this ?
thanks in advance....
Below is the screen-shot of current occuring situation, .....
Here i have made a button using javafx scene builder , and then in the controller of the fxml file (.java file) i am trying to set the image (shown in orange box in snapshot) to that button by using setGraphics property of button ..... i just need that button to be of following shape ...
You'd better customize your button via CSS. Here goes tutorial. What you are trying to do is to modify button picture (which is empty by default). I guess this wasn't your exact purpose.
button.setGraphic(null)
// worked for me.

Resources