Have 4 buttons in android studio and a picture.

Here i have create different three activities
MainActivity for main output, OtherNews for other news and third one is MessagesPage for display entertainment channel
Code MainActivity.java
package com.example.buttondemo;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.net.Uri;
public class MainActivity extends Activity {
Button
btncnn,btnnytimes,btnothernews,btnmessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//total foutr button as per your requirment
btncnn=(Button)findViewById(R.id.button1);//for cnn channel
btnnytimes=(Button)findViewById(R.id.button2);//for nytimes
channel
btnothernews=(Button)findViewById(R.id.button3);//for othernews
channel
btnmessage=(Button)findViewById(R.id.button4);//for message
button
btncnn.setOnClickListener(new OnClickListener() {
@Override
public void
onClick(View arg0) {//when user click on button intent fire
Intent CNNChannel=new
Intent(Intent.ACTION_VIEW,Uri.parse("https://edition.cnn.com/"));
startActivity(CNNChannel);
}
});
btnnytimes.setOnClickListener(new OnClickListener() {//when user
click on button intent fire
@Override
public void
onClick(View arg0) {//when user click on button intent fire
Intent CNNChannel=new
Intent(Intent.ACTION_VIEW,Uri.parse("https://www.nytimes.com/"));
startActivity(CNNChannel);
}
});
btnothernews.setOnClickListener(new OnClickListener() {
//when user click on button intent fire
@Override
public void
onClick(View arg0) {//when user click on button intent fire and go
to othernews activityes
Intent myIntent = new
Intent(MainActivity.this,OtherNews.class);
startActivityForResult(myIntent, 0);
}
});
btnmessage.setOnClickListener(new OnClickListener() {
//when user click on button intent fire
@Override
public void
onClick(View arg0) {//when user click on button intent fire and go
to messagepage activity
Intent myIntent = new
Intent(MainActivity.this,MessagesPage.class);
startActivityForResult(myIntent, 0);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Code activity_main.xml file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView1"
android:layout_below="@+id/imageView1"
android:layout_marginTop="27dp"
android:text="Click For CNN News!" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="24dp"
android:layout_marginTop="29dp"
android:src="@drawable/images" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_alignRight="@+id/button2"
android:layout_below="@+id/button3"
android:text="Click For Messages!" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_alignRight="@+id/button2"
android:layout_below="@+id/button2"
android:text="Click For Other News!" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:text="Click For NYTIMES NEWS!" />
</RelativeLayout>
Code OtherNews.java
package com.example.buttondemo;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class OtherNews extends Activity {
Button btnsport,btnmessage;//button for sport and
message
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_other_news);
btnsport=(Button)findViewById(R.id.button1);
btnmessage=(Button)findViewById(R.id.button2);
//on click event
btnsport.setOnClickListener(new
OnClickListener() {
@Override
public void
onClick(View arg0) {//when user click on button intent fire
Intent SPORTChannel=new
Intent(Intent.ACTION_VIEW,Uri.parse("https://www.skysports.com/watch/sky-sports-cricket"));
startActivity(SPORTChannel);
}
});
btnmessage.setOnClickListener(new
OnClickListener() {
@Override
public void
onClick(View arg0) {// when user click on button message display
with toast
Toast toast =
Toast.makeText(getApplicationContext(),
"This is a Others news Activity and click above
button so you can watch sports channel",
Toast.LENGTH_SHORT);
toast.show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds
items to the action bar if it is present.
getMenuInflater().inflate(R.menu.other_news, menu);
return true;
}
}
Code activity_other_news.xml file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".OtherNews" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="41dp"
android:layout_marginTop="63dp"
android:text="SportChannel" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="21dp"
android:text="SportMessage" />
</RelativeLayout>
code MessagesPage.java
package com.example.buttondemo;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MessagesPage extends Activity {
Button btnentertainment,btnmessage;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messages_page);
btnentertainment=(Button)findViewById(R.id.button1);
btnmessage=(Button)findViewById(R.id.button2);
btnentertainment.setOnClickListener(new OnClickListener()
{
@Override
public void
onClick(View arg0) {//when user click on button intent fire
Intent SPORTChannel=new
Intent(Intent.ACTION_VIEW,Uri.parse("https://indianexpress.com/section/entertainment/"));
startActivity(SPORTChannel);
}
});
btnmessage.setOnClickListener(new
OnClickListener() {
@Override
public void
onClick(View arg0) {// when user click on button message display
with toast
Toast toast =
Toast.makeText(getApplicationContext(),
"This is a entertainment news Activity and click
above button so you can wathes entertainment channel",
Toast.LENGTH_SHORT);
toast.show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds
items to the action bar if it is present.
getMenuInflater().inflate(R.menu.messages_page, menu);
return true;
}
}
Code activity_messages_page.xml file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MessagesPage" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="45dp"
android:layout_marginTop="41dp"
android:text="Entertainment News" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="36dp"
android:text="Message entertainment" />
</RelativeLayout>
ShreenShot Of Code:



Output





Thank you if you have any query regarding above answer please ask me in comment box.
if you like my work appreciate with thumbs up.
Thank You.
Can
anyone please help me create this structure with buttons in java,
android studio?
1 2 3 4 Hello world 6 7
1 2 3 4 Hello world 6 7
in android studio how to have a URL represent an image?
4. coverURL: String - A URL to the image representing the book cover
Android Studio (Java) Develop an android app that contains two fragments displayed on one activity. The bottom fragment contains / displays several rows of individual buttons and each of these buttons resemble a letter of the alphabet such as the first button "A" second button "B" etc.. all the way to Z as well as buttons for the numbers 0 - 9. Once a user clicks a button, the corresponding letter or number button they pressed should display in the...
(Android Studio)
Create a camera app that allows the user to upload a picture
from their phone camera gallery, see the picture via summary page,
and edit the picture as well. Clicking on "Insert picture here from
camera photo gallery" in the add page will allow the user to upload
a picture from their existing camera photo gallery on their phone.
The user can choose where to save the picture, starting with
Picture 1-5. Once they choose where to save...
(Mobile-Android Studio) Hello. Thank you for coming to help me:) I am using the Andriod studio on mac. and using Java code to develop. and Please start with basic activity with constraints layout (not empty). (audio file is not given, let's say there any audio file). I just would like to see the codes how it works. Thank you very much. I would like to know how to write a program that includes two buttons called plays Play and Stop....
Hi ?, I have a question in the android studio, I am using button sheet to display information, I want to display the button sheet depending on condition, display or hidden and, when collapse and expand the bottom sheet is repeated on background how to solve this problem?
I should show tables with info after clicking on the buttons in
Android Studio. I still can not get what I should write inside
OnClick function and how to use containers for printing tables.
Please help me!
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
LinearLayout container;
ListView ListView1;
ListView ListView2;
ListView ListView3;
@Override
protected void onCreate(Bundle savedInstanceState)...
Create a Lottery application in Android Studio that simulates a lottery game. The application should allow the play to type in number to generate five numbers and one red ball. The constructor should use the Random class to generate a random number in the range of 1 through 69 for the red ball 1 through 26. In Android Studio
Using java in android studio, I need help in making a barcode scanner thanks for the help
What is the default orientation for the LinearLayout ViewGroup in android studio? please answer this question in details, Thank you.