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) 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....
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)...
What is the default orientation for the LinearLayout ViewGroup in android studio? please answer this question in details, Thank you.
On Android studio, how to call a phone number from a button? Like when the user click on a buttom on the aplication, it direct him to a phone call thanks
how to solve this issue with line of code on android studio java bluetooth connection. Android Manifestxml | MainAcIM Java A L LIVILY_Malli. private static final int REQUEST ENABLE BT = 0; private static final int REQUEST DISCOVER BT = 1 TextView mStatusBlueTv, PairedTv; ImageView mBlueIv; Button monBtn, moffBtn, nDiscoverBtn, mPaired 1 BluetoothAdapter mBlueAdapter; -- EA @Override protected void onoreate (Bundle savedInstanceState super.oncreate (savedInstanceState) -- main= Cannot resolve method 'onCreate(android.os.Bundle) mStatusblue'lv = mStatusBluelv.rindViewById(R. m PairedTy = Pairedtv. findViewById(R.id.p mBluelv =...
COP 2660, Programming for Mobile Devices Using Android Studio Create the working application as You can design a different listView of your choice. Try to have at-least 3 items in your listView. Zip your project file link and upload the code Purpose: is designed to assess the implementation of ListView activities.
In Android Studio, how can I make a shape change color based on information read from a database? (Java and xml code would be most helpful)