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

Apps Android Application Development

I am developing an app in android and the search button in the application needs to be linked to a website. Instead of the website opening up on the android emulator the source code appears. Can anyone help me with this...

I have pasted the code below...

package com.apache;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ApacheConnection extends Activity {

Button bt;
TextView textView1;
TextView textView2;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt = (Button) findViewById(R.id.button1);
textView1 = (TextView) findViewById(R.id.editText1);
textView2 = (TextView) findViewById(R.id.editText2);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
textView2.setText("");

try {
/*Apache HttpClient Library*/
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://google.com");
HttpResponse response = client.execute(request);
/* response code*/
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
Log.d("output:",line);
}
} catch (Exception exe) {
exe.printStackTrace();
}
}
});

}
}
------------------------------------------------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="Enter URL"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:text="http://www.nancybishop.com/"
android:layout_height="wrap_content">
</EditText>

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


<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="fill_parent">
</EditText>

</LinearLayout>

Thanks a lot
P
 
Welcome to AF! I am going to move your thread to our app dev forum and see if we can get you some better replies :)
 
You're looking for the WebView widget, which displays web sites like a browser. And don't try to retrieve the page yourself, just call loadUrl :

Code:
WebView w=new WebView(this);
w.getSettings().setJavaScriptEnabled(true);
setContentView(w);
w.loadUrl("http://www.nancybishop.com/");
 
Back
Top Bottom