1. Check out our companion app, Forums for Android! Download from Google Play

problem in connection from android to mysql(wamp)

Discussion in 'Post Your Codes' started by nagaraja, Mar 16, 2011.

  1. nagaraja

    nagaraja New Member
    Thread Starter
    5

    Mar 16, 2011
    2
    0
    5
    public class motor extends Activity {
    public static final int REQUEST_CODE=1;
    /** Called when the activity is first created. */
    Button b;
    RadioButton r1;
    EditText tv;
    String text;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.motor);
    b=(Button)findViewById(R.id.motor_submit);
    b.setOnClickListener(new clickhandler());
    tv=(EditText)findViewById(R.id.widget32);
    }
    public class clickhandler implements OnClickListener
    {
    public void onClick(View v)
    {
    if(v==b)
    {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://localhost/getAllPeopleBornAfter.php");

    try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
    //ameValuePairs.add(new BasicNameValuePair("mydata", "Mek Mek"));
    // httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    InputStream is = response.getEntity().getContent();
    BufferedInputStream bis = new BufferedInputStream(is);
    ByteArrayBuffer baf = new ByteArrayBuffer(20);
    int current = 0;
    while((current = bis.read()) != -1){
    baf.append((byte)current);
    }
    text = new String(baf.toByteArray());
    tv.setText(text.toString());
    } catch (ClientProtocolException e) { tv.setText(e.toString());
    // TODO Auto-generated catch block
    } catch (IOException e) {
    // TODO Auto-generated catch block
    }

    //Intent intent=new Intent(motor.this,motor1.class);
    //startActivityForResult(intent,REQUEST_CODE);
    }

    }
    }

    }
     

    Advertisement

Share This Page

Loading...