android向服务器发送请求,android – 如何向服务器发送HTTP POST请求请求

您好我在点击显示日期选择器对话框和时间选择器对话框中使用两个按钮.

我有一个旋转器.

我想将用户输入值发送到PHP服务器.

我该怎么做客户端代码?

这是我的代码:

public class DineOutActivity extends Activity {

private TextView mDateDisplay;

private Button mPickDate;

private int mYear;

private int mMonth;

private int mDay;

/******************time picker**************/

private TextView mTimeDisplay;

private Button mPickTime;

private int mHour;

private int mMinute;

private int mAmPm;

static final int TIME_DIALOG_ID=1;

static final int DATE_DIALOG_ID = 0;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

/********************spinner***********/

Spinner food = (Spinner) findViewById(R.id.spinner1);

ArrayAdapter foodadapter = ArrayAdapter.createFromResource(

this,R.array.item_array,android.R.layout.simple_spinner_item);

foodadapter.setDropDownViewResource(R.layout.spinner_layout);

food.setAdapter(foodadapter);

/**pick date*/

mDateDisplay = (TextView) findViewById(R.id.textView2);

mTimeDisplay = (TextView) findViewById(R.id.textView4);

mPickDate = (Button) findViewById(R.id.button2);

/**pick time**/

mPickTime=(Button)findViewById(R.id.button3);

// add a click listener to the button

mPickTime.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

showDialog(TIME_DIALOG_ID);

}

});

// get the current time

final Calendar c=Calendar.getInstance();

mHour=c.get(Calendar.HOUR_OF_DAY);

mMinute=c.get(Calendar.MINUTE);

mAmPm = c.get(Calendar.AM_PM);

// display the current date

upTimeDisplay();

/*****************************pick date***********************************/

// add a click listener to the button

mPickDate.setOnClickListener(new View.OnClickListener() {

public void onClick(View v1) {

showDialog(DATE_DIALOG_ID);

}

});

// get the current date

final Calendar date = Calendar.getInstance();

mYear = date.get(Calendar.YEAR);

mMonth = date.get(Calendar.MONTH);

mDay = date.get(Calendar.DAY_OF_MONTH);

int mDst = date.get(Calendar.AM_PM);

int mAmPm = date.get(Calendar.DST_OFFSET);

// display the current date (this method is below)

updateDisplay();

}

// updates the date in the TextView

private void upTimeDisplay()

{

// mTimeDisplay.setText(new

// StringBuilder().append(pad(mHour)).append(":").append(pad(mMinute)).append(pad(mAmPm)));

mTimeDisplay.setText(new

StringBuilder().append(mHour).append(":").append(mMinute));

mTimeDisplay.setTextColor(R.color.green);

}

/** private Object pad(int mMinute2) {

if(mMinute2>=10)

return String.valueOf(mMinute2);

else

return "0"+String.valueOf(mMinute2);

}**/

private TimePickerDialog.OnTimeSetListener mtimeSetListener=new

TimePickerDialog.OnTimeSetListener() {

public void onTimeSet(TimePicker view,int hourOfDay,int minute) {

mHour=hourOfDay;

mMinute=minute;

int ampm;

upTimeDisplay();

}

};

private void updateDisplay() {

mDateDisplay.setText(new StringBuilder()

// Month is 0 based so add 1

.append(mMonth + 1).append("-")

.append(mDay).append("-")

.append(mYear).append(" "));

mDateDisplay.setTextColor(R.color.green);

// .append(mHour).append("_")

// .append(mMinute).append("_")));

}

// the callback received when the user "sets" the date in the dialog

private DatePickerDialog.OnDateSetListener mDateSetListener =

new DatePickerDialog.OnDateSetListener() {

public void onDateSet(DatePicker view,int year,int monthOfYear,int dayOfMonth) {

mYear = year;

mMonth = monthOfYear;

mDay = dayOfMonth;

updateDisplay();

}

};

@Override

protected Dialog onCreateDialog(int id) {

switch (id) {

case DATE_DIALOG_ID:

return new DatePickerDialog(this,mDateSetListener,mYear,mMonth,mDay);

case TIME_DIALOG_ID:

return new TimePickerDialog(this,mtimeSetListener,mHour,mMinute,false);

}

return null;

}

我使用mPickDate作为打开DatePickerDialog的按钮

mPickTime作为单击打开TimePicker对话框的按钮

一个Spinner(spinner1)获取项目列表.

mDateDisplay显示用户在单击DatePickerDialog后编辑的日期.

mTimeDisplay显示用户在单击TimePickerDialog后编辑的时间.

我希望DatePickerDialog,TimePickerDialog和spinner的用户输入的字符串值作为HTTP post发送到服务器.请告诉我怎么做?我想要详细的代码.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值