I\'m looking for the code to run this or you just want how to put this code into
ID: 3583538 • Letter: I
Question
I'm looking for the code to run this or you just want how to put this code into android studio to make it run on your device. Please find below code and help me
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle ;
import android.view.View;
import android.view.View.OnClickListener;
public class Fivestar extends Activity implements OnClickListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout.fivestar) ;
View Button = findViewById(R.id.v7) ;
Button.setOnClickListener((OnClickListener) this);
View Button1 = findViewById(R.id.b8) ;
Button1.setOnClickListener((OnClickListener) this);
View Button2 = findViewById(R.id.b9) ;
Button2.setOnClickListener((OnClickListener) this);
View Button3 = findViewById(R.id.b10) ;
Button3.setOnClickListener((OnClickListener) this);
View Button4 = findViewById(R.id.b11) ;
Button4.setOnClickListener((OnClickListener) this);
View Button5 = findViewById(R.id.b12) ;
Button5.setOnClickListener((OnClickListener) this);
View Button6 = findViewById(R.id.b13) ;
Button6.setOnClickListener((OnClickListener) this);
View Button7 = findViewById(R.id.b14) ;
Button7.setOnClickListener((OnClickListener) this);}
public void onClick(View v) {
switch (v.getId()) {
case R.id.v7:
Intent i = new Intent(this, Viventa.class);
startActivity(i);
break;
case R.id.b8 : Intent j = new Intent(this, Hyatt.class) ;
startActivity(j) ;
break ;
case R.id.b9 : Intent k = new Intent(this, Lalit.class) ;
startActivity(k) ;
break ;
case R.id.b10 : Intent l = new Intent(this, Lodhi.class) ;
startActivity(l) ;
break ;
case R.id.b11 : Intent m = new Intent(this, Leela.class) ;
startActivity(m) ;
break ;
case R.id.b12 : Intent n = new Intent(this, Taj.class) ;
startActivity(n) ;
break ;
case R.id.b13 : Intent o = new Intent(this, Grand.class) ;
startActivity(o) ;
break ;
case R.id.b14 : Intent p = new Intent(this, Oberoi.class) ;
startActivity(p) ;
break ;
}
}
}
import android.app.Activity;
import android.os.Bundle ;
public class Fourstar extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout.fourstar) ;
}
}
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Grand extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState) ;
setContentView(R.layout.grand) ;
View b1 = (Button)findViewById(R.id.g1) ;
b1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://www.grandcityhotels.com")) ;
startActivity(i) ;
}
}) ;
View b2 = (Button)findViewById(R.id.g2) ;
b2.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+49308870880")) ;
startActivity(i) ;
}
}) ;
View b3 = (Button)findViewById(R.id.g3) ;
b3.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+31-20-6 54 15 62")) ;
startActivity(i) ;
}
}) ;
View b4 = (Button)findViewById(R.id.g4) ;
b4.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+7916 026 1133")) ;
startActivity(i) ;
}
}) ;
View b6 = (Button)findViewById(R.id.g5) ;
b6.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+33-1-5343 7900")) ;
startActivity(i) ;
}
}) ;
View b5 = (Button)findViewById(R.id.g6) ;
b5.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:86 63 59 15 35")) ;
startActivity(i) ;
}
}) ;
View b7 = (Button)findViewById(R.id.g7) ;
b7.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+46 8 545 259 55")) ;
startActivity(i) ;
}
}) ;
View b8 = (Button)findViewById(R.id.g8) ;
b8.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+34 – 91- 458 57 27")) ;
startActivity(i) ;
}
}) ;
View b9 = (Button)findViewById(R.id.g9) ;
b9.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+39 - 02 - 43 45 83 11")) ;
startActivity(i) ;
}
}) ;
}
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class H1Activity extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 2000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.h1);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(H1Activity.this, H2.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle ;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class H2 extends Activity implements OnClickListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState) ;
setContentView(R.layout.hb2) ;
View b4 = (Button) findViewById(R.id.b4) ;
b4.setOnClickListener(this) ;
b4.setSelected(true) ;
View b6 = (Button) findViewById(R.id.b6) ;
b6.setOnClickListener(this) ;
b6.setSelected(true) ;
}
public void onClick(View V){
if(V.getId() == R.id.b4)
{
Intent i = new Intent(this, H6.class) ;
startActivity(i) ;
}
else
{
Intent j = new Intent(this, H8.class) ;
startActivity(j) ;
}
}
}
import android.app.Activity ;
import android.content.Intent;
import android.os.Bundle ;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class H6 extends Activity implements OnClickListener{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState) ;
setContentView(R.layout.searchhotels) ;
View b4 = (Button) findViewById(R.id.search) ;
b4.setOnClickListener(this) ;
b4.setSelected(true) ;
}
public void onClick(View V){
if(V.getId() == R.id.search)
{
Intent i = new Intent(this, Fivestar.class) ;
startActivity(i) ;
}
}
}
import android.app.Activity ;
import android.content.Intent;
import android.os.Bundle ;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class H8 extends Activity implements OnClickListener{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState) ;
setContentView(R.layout.hreservation) ;
View b1 = (Button) findViewById(R.id.b1) ;
b1.setOnClickListener(this) ;
b1.setSelected(true) ;
View b2 = (Button) findViewById(R.id.b2) ;
b2.setOnClickListener(this) ;
b2.setSelected(true) ;
}
public void onClick(View V){
if(V.getId()== R.id.b1){
Intent i = new Intent(this, Fivestar.class) ;
startActivity(i) ;
}
else{
Intent j = new Intent(this, Fourstar.class);
startActivity(j) ;
}
}
}
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Hyatt extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState) ;
setContentView(R.layout.hyatt) ;
View b1 = (Button)findViewById(R.id.h1) ;
b1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://www.hyatt.com")) ;
startActivity(i) ;
}
}) ;
View b2 = (Button)findViewById(R.id.h2) ;
b2.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+541152184518")) ;
startActivity(i) ;
}
}) ;
View b3 = (Button)findViewById(R.id.h3) ;
b3.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+551132578855")) ;
startActivity(i) ;
}
}) ;
View b4 = (Button)findViewById(R.id.h4) ;
b4.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+5716100599")) ;
startActivity(i) ;
}
}) ;
View b5 = (Button)findViewById(R.id.h5) ;
b5.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+14025376835")) ;
startActivity(i) ;
}
}) ;
View b6 = (Button)findViewById(R.id.h6) ;
b6.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:018000050000")) ;
startActivity(i) ;
}
}) ;
View b7 = (Button)findViewById(R.id.h7) ;
b7.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:18002331234")) ;
startActivity(i) ;
}
}) ;
View b8 = (Button)findViewById(R.id.h8) ;
b8.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:131234")) ;
startActivity(i) ;
}
}) ;
View b9 = (Button)findViewById(R.id.h9) ;
b9.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+85229561234")) ;
startActivity(i) ;
}
}) ;
View b10 = (Button)findViewById(R.id.h10) ;
b10.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+18001221234")) ;
startActivity(i) ;
}
}) ;
View b11 = (Button)findViewById(R.id.h11) ;
b11.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:0120512343")) ;
startActivity(i) ;
}
}) ;
View b12 = (Button)findViewById(R.id.h12) ;
b12.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+80002001234")) ;
startActivity(i) ;
}
}) ;
View b13 = (Button)findViewById(R.id.h13) ;
b13.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:1800818188")) ;
startActivity(i) ;
}
}) ;
View b14 = (Button)findViewById(R.id.h14) ;
b14.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:0800441234")) ;
startActivity(i) ;
}
}) ;
View b15 = (Button)findViewById(R.id.h15) ;
b15.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:80011085")) ;
startActivity(i) ;
}
}) ;
View b16 = (Button)findViewById(R.id.h16) ;
b16.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+8651255001234")) ;
startActivity(i) ;
}
}) ;
View b17 = (Button)findViewById(R.id.h17) ;
b17.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:+6531587887")) ;
startActivity(i) ;
}
}) ;
View b18 = (Button)findViewById(R.id.h18) ;
b18.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(android.content.Intent.ACTION_DIAL,
Uri.parse("tel:08009731234")) ;
startActivity(i) ;
}
}) ;
}
}
Explanation / Answer
First, I want to tell something. The code is ok, but few things are also needed for you to run this code. Those are the XML files. In android, you are having class files to have code and XML files for designing the layouts. You have entered the code, so please get or create all the XML files as per the requirement as it is not mentioned; otherwise you won't be able to run this code.
I am listing those XML files that are used in this code. You can find the same which are written as:
setContentView(R.layout.name_of_the_file) in your provided code.
1. fivestar.xml
2. fourstar.xml
3. grand.xml
4.. h1.xml
5. hb2.xml
6. searchhotels.xml
7. hreservation.xml
8. hyatt.xml
Now, open android studio.
Select Start a new Android Studio project.
Specify the names.
Then specify the API level. Choose from available ones. I advise to go with GingerBread.
In the next, select Empty Activity.
Next, let that name 'activity_main' as it is. For Java/Class name, change it to H1Activity
Finish.
You are having a project open having 2 files specifically, 1 is H1Activity.java (class file) 2nd is activity_main.xml which you can find under app/res/layout directory. You have to do 2 things.
1. Copy all those xml files (listed above) into that layout folder. Then remove that xml file that was auto generated.
Now you are done with xml. Now comes the code. So, for that do the below thing for every segment in your provided code.
2. go to the directory containing H1Activity. Right click there, select new Java Class and then for every statement in ayour code that seems like : public class class_name ..... create a separate Java i.e. class file.
Note: Separate the code from import statements.. When next time import statements block is coming, it is part of next file. This is easy to do and I can't write the whole files else the answer will be so much long.
Replace the auto-generated H1Activity.java file's code with the code you provided.
After doing this, you have everything ready. Save project and press run button displayed there or press Shift + F10. Select an appropriate emulator and press OK. Wait till the virtual device is getting loaded. After that, it will automatically install and run your app inside it.
If you want to run it in your phone, go to settings -> developer options -> Enable USB Debugging.
After that, you will find your device list along with those emulator i.e. virtual devices. Select it and press OK.
If you have any doubt please let me know. I will solve it for sure. For n number of times. Feel free to ask. This is the exact procedure to your question. Thank you :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.