안녕하세요 저는 클릭 할 때 날짜 선택기 대화 상자와 시간 선택기 대화 상자에 두 개의 버튼을 사용하고 있습니다. 나는 회 전자가있다.서버에 HTTP POST 요청에 대한 요청을 보내는 방법
사용자 입력 값을 PHP 서버에 보내려고합니다. 클라이언트 측 코드는 어떻게해야합니까? 여기
내 코드입니다 : 내가 클릭에 TimePicker 대화 상자를 표시하는 버튼으로 DatePickerDialog mPickTime에 표시하는 버튼으로 mPickDate을 사용하고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<CharSequence> 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;
}
한 회 전자 (spinner1)의 목록을 가져옵니다 목. DatePickerDialog를 클릭 한 후 사용자가 편집 한 날짜를 표시하는 mDateDisplay입니다. TimePickerDialog를 클릭 한 후 사용자가 편집 한 시간을 표시하는 mTimeDisplay입니다.
DatePickerDialog, TimePickerDialog 및 스피너의 사용자 입력 문자열 값을 HTTP 게시물로 서버에 보내고 싶습니다. 어떻게할까요? 세부 코드가 필요합니다.
죄송하지만 사용자의 입력에서의 NameValuePair을 얻을, 나는 그것이 대화 상자와지도 방법을 의미하고 통과하실 수 있습니다 스피너. – divaNilisha
또한 서버에 날짜와 시간을 저장합니다. "YYYY/MM/DD"또는 "DD/MM/YYYY"형식을 어떻게 만들지 – divaNilisha
이 코드를 직접 작성 했습니까? 당신이 나에게 이런 질문을하는 건 전혀 ... –