Hi:

 

I am developing an app in android and the search button in the application
needs to be linked to a website and I am unable to do that - 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

 

 

 

Thanks

..Priya

 

Simply-Logic Technologies

Chennai 600 044, India

Tel:+91-44-22410162

Mobile:+91-98410-85872

 

www.simply-logic.com

For the Right Reasons

 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to