Well i have done your task just copy and paste it.Its complete task.If you still got any errors comment here.
public class Confirm_instant_top_up extends Activity {
TextView network;
TextView names;
TextView amount;
TextView phone_number;
TextView email_address;
String ntwk;
String nms;
String amt;
String phone;
String email;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.confirm_instant_top_up);
network = (TextView) findViewById(R.id.network);
names = (TextView) findViewById(R.id.names);
amount = (TextView) findViewById(R.id.amount);
phone_number = (TextView) findViewById(R.id.phone_number);
email_address = (TextView) findViewById(R.id.email_address);
Intent intent = getIntent();
ntwk = intent.getStringExtra("network");
nms = intent.getStringExtra("names");
amt = intent.getStringExtra("amount");
phone = intent.getStringExtra("phone");
email = intent.getStringExtra("email");
network.setText(ntwk);
names.setText(nms);
amount.setText(amt);
phone_number.setText(phone);
email_address.setText(email);
Button btnOk = (Button) findViewById(R.id.btn_ok);
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BackGroundTask task = new BackGroundTask();
task.execute();
}
});
class BackGroundTask extends AsyncTask<String,Void,Void> {
public BackGroundTask()
{
super();
}
@Override
protected void onPreExecute() {
}
@Override
protected Void doInBackground(String...params) {
if(ntwk.length()>0) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/test/confirmPayment.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("network", ntwk));
nameValuePairs.add(new BasicNameValuePair("names", nms));
nameValuePairs.add(new BasicNameValuePair("amount", amt));
nameValuePairs.add(new BasicNameValuePair("phone_number", phone));
nameValuePairs.add(new BasicNameValuePair("email_address", email));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
Toast.makeText(getBaseContext(),"Sent",Toast.LENGTH_SHORT).show();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
//display message if text field is empty
Toast.makeText(getBaseContext(),"All fields are required",Toast.LENGTH_SHORT).show();
}
return null;
}
@Override
protected Void onPostExecute() {
return null;
}
}
}
}
Also dont forget to add permissions in the AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />