Go Back   Android Forums > Android Discussion > Android Games > Post Your Codes

test: Reply
 
LinkBack Thread Tools
Old March 16th, 2011, 06:06 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Mar 2011
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default problem in connection from android to mysql(wamp)

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);
}

}
}

}

Advertisements
nagaraja is offline  
Reply With Quote
sponsored links
Reply


Go Back   Android Forums > Android Discussion > Android Games > Post Your Codes
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:23 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.