• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps So I wanna make an app...

GalaxyNexus

Android Enthusiast
I've been making some pretty lame apps that link to websites on AppsGeyser (which takes up half of my ad space). I'm wondering if anyone could help/explain to me how I would make an app that would link to a website (using eclipse). If someone could show me an example then that would be awesome. Btw if anyone knows how to code the exact same thing for Amazon then it would be sweet.

I'm a young dev under the age of 18 that's just looking for some help from his elders..

Thanks in advance
 
What i did to do this was. In xml I created a button. something like this

<Button
android:id="@+id/facebook"
android:layout_width="150dp"
android:layout_height="60dp"
android:background="@drawable/customface"

/>
After that in your Java class

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main); ///<--set to the xml file you have your button on

Button facebook = (Button) findViewById(R.id.facebook);

facebook.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
// TODO Auto-generated method stub
Uri uriUrl = Uri.parse("https://m.facebook.com/nationalcleaners");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
});
 
What i did to do this was. In xml I created a button. something like this

<Button
android:id="@+id/facebook"
android:layout_width="150dp"
android:layout_height="60dp"
android:background="@drawable/customface"

/>
After that in your Java class

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main); ///<--set to the xml file you have your button on

Button facebook = (Button) findViewById(R.id.facebook);

facebook.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
// TODO Auto-generated method stub
Uri uriUrl = Uri.parse("https://m.facebook.com/nationalcleaners");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
});

Thanks
 
Give me a clear idea on what your trying to do... Lets say you want a button in your main.xml file. Ad your button to the view. It should look something like this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

</LinearLayout>

The above is your main.xml with a button in it. After doing that, close the main.xml file. Go to src> com.package and open your Main.java class, or what ever you named your app/activity.java class. But for now I'll call it Main.java... It should look like this


package com.package.name;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class Main extends Activity {


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);<--- this line of code tells your class this is the xml
file your working on...

Button cleverbot = (Button) findViewById(R.id.button1);

cleverbot.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) { /// make sure it reads (View view) not (View v)
// TODO Auto-generated method stub
Uri uriUrl = Uri.parse("https://cleverbot.com/-i_am_cleverbot");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
});
}
}
This should work....

Also, in your manifest. Make sure you use permission--->

<uses-permission android:name="android.permission.INTERNET"/>
 
Give me a clear idea on what your trying to do... Lets say you want a button in your main.xml file. Ad your button to the view. It should look something like this

&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:orientation=&quot;vertical&quot; &gt;

&lt;Button
android:id=&quot;@+id/button1&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;Button&quot; /&gt;

&lt;/LinearLayout&gt;

The above is your main.xml with a button in it. After doing that, close the main.xml file. Go to src&gt; com.package and open your Main.java class, or what ever you named your app/activity.java class. But for now I'll call it Main.java... It should look like this


package com.package.name;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class Main extends Activity {


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);&lt;--- this line of code tells your class this is the xml
file your working on...

Button cleverbot = (Button) findViewById(R.id.button1);

cleverbot.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) { /// make sure it reads (View view) not (View v)
// TODO Auto-generated method stub
Uri uriUrl = Uri.parse(&quot;https://cleverbot.com/-i_am_cleverbot&quot;);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
});
}
}
This should work....

Also, in your manifest. Make sure you use permission---&gt;

&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;

What do I put for the r.Id.button1; _________
 
What ever you want it to be... Its only a reference to link to your xml button to the code in java. If you look at the xml code I gave you, it says (android:id="@+id/button1") the findViewById(R.id.button1); is telling java this is the buuton your going to control... I'm going to put you on to something that can help, if you haven't already started watching them... On YouTube theres a channel call "thenewboston" I'm going to give you a link. Theres 200 videos, that can show you how to do things. You really don't have to watch all of them... But I=it would help you a lot if you did... If your not trying to... Just find witch videos might help you... Go to this link-----> Android Application Development Tutorials - YouTube
 
U can have it like this

<Button
android:id="@+id/cleverbot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

then your would be

android:id="@+id/cleverbot"

or

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

then your would be

android:id="@+id/b1"

you can make it what ever you want it to be... Its just a link between both codes, xml and java class
 
U can have it like this

<Button
android:id="@+id/cleverbot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

then your would be

android:id="@+id/cleverbot"

or

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

then your would be

android:id="@+id/b1"

you can make it what ever you want it to be... Its just a link between both codes, xml and java class

OOOOOOOOOOOOOHHHHH thanks. That has been my problem
 
package com.cleverbot.free;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class CleverbotActivity extends Activity {


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

Button cleverbot = (Button) findViewById(R.id.cleverbot);

cleverbot.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) { /// make sure it reads (View view) not (View v)
// TODO Auto-generated method stub
Uri uriUrl = Uri.parse("https://cleverbot.com/-i_am_cleverbot");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
});
}
}

I have the red squiggly line under the id, what do i do?

It says: id cannot be resolved or is not a field

2 quick fixes availible
create field id in type R
create constant id in type R
[/LIST]
 
I think where getting are self's mixed up here

Button cleverbot = (Button) findViewById(R.id.cleverbot); cleverbot is your id link name... R is for your res folder, id is saying theres a id, cleverbot is the id... (R.id.cleverbot)... you have this all right in your java class... Now in your res folder open the xml file where the button is it... In the xml it should look like this...

<Button
android:id="@+id/cleverbot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

this is your id, android:id="@+id/cleverbot"... It should look like this... see the @ for at, + for plus, id for id, cleverbot is the id... This line of code (R.id.cleverbot) in java is looking for this line of code in xml "@+id/cleverbot"

If your still having truble, make sure the setContentView in your java class you just posted is set to the name of the xml file that your button is in... If that right... Then chage the id name from cleverbot to button1, like this... in java (R.id.button1) and in xml
"@+id/button1"
 
Back
Top Bottom