|
|
|
android DatePickerDialog ช่วยดูหน่อยมันขึ้นแต่ค่าแรก พอจะสร้างอีกตัวมันกลับไปทับค่าแรก |
|
|
|
|
|
|
|
ผมจะแยกเป็น edittext 2ตัว แต่ละตัวรับ ค่าวันที่แยกกัน
โค้ดที่ผมเขียนค่าแรกรับได้ พอจะรับค่าที่2 มันกลับไปทับค่าแรก
Code (Android-Java)
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
public class ConcludeTime extends Activity {
// ตัวแปละtime
private EditText editT123;
private EditText editT124;
private ImageView btn123;
private ImageView btn124;
private int mYear;
private int mMonth;
private int mDay;
static final int DATE_DIALOG_ID = 0;
private int mYear2;
private int mMonth2;
private int mDay2;
static final int DATE_DIALOG_ID2 = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.concludetime);
editT123 = (EditText) findViewById(R.id.edtday123);
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
updateCurrentDate();
editT124 = (EditText) findViewById(R.id.edtday124);
final Calendar e = Calendar.getInstance();
mYear2 = e.get(Calendar.YEAR);
mMonth2 = e.get(Calendar.MONTH);
mDay2 = e.get(Calendar.DAY_OF_MONTH);
updateCurrentDate2();
// เวลาเริ่ม ************
btn123 = (ImageView) findViewById(R.id.btnday123);
btn123.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
// ##สิ้นสุด*********************##
btn124 = (ImageView) findViewById(R.id.btnday124);
btn124.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(DATE_DIALOG_ID2);
}
});
final ImageView btnback = (ImageView) findViewById(R.id.btnback);
btnback.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent newActivity = new Intent(ConcludeTime.this,Conclude.class);
startActivity(newActivity);
}
});
}
//เริ่ม เวลาเรียกใช้ ************
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,
mDay);
//break;
}
switch (id) {
case DATE_DIALOG_ID2:
return new DatePickerDialog(this, mDateSetListener2, mYear2, mMonth2,
mDay2);
}
return null;
}
// updates the date we display in the editText
private void updateCurrentDate() {
editT123.setText(new StringBuilder()
// Month is 0 based so add 1
.append(mDay).append("-").append(mMonth + 1).append("-")
.append(mYear).append(" "));
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateCurrentDate();
}
};
//สิ้นสุด เวลาเรียกใช้ ************
// updates the date we display in the editText
private void updateCurrentDate2() {
editT124.setText(new StringBuilder()
// Month is 0 based so add 1
.append(mDay2).append("-").append(mMonth2 + 1).append("-")
.append(mYear2).append(" "));
}
private DatePickerDialog.OnDateSetListener mDateSetListener2 = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year2, int monthOfYear2,
int dayOfMonth2) {
mYear2 = year2;
mMonth2 = monthOfYear2;
mDay2 = dayOfMonth2;
updateCurrentDate2();
}
};
}
Tag : Mobile, Android
|
|
|
|
|
|
Date :
2014-02-15 07:38:54 |
By :
bbza |
View :
1032 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Debug ดูเลยครับ ดู Code แบบนี้ไล่ยากครับ
|
|
|
|
|
Date :
2014-02-15 09:00:44 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ได้แล้ว
Code (Java)
static final int DATE_DIALOG_ID2 = 0;
แก้เป็น
Code (Java)
static final int DATE_DIALOG_ID2 = 1;
จะบ้าตาย
|
|
|
|
|
Date :
2014-02-16 03:58:00 |
By :
bbza |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2014-02-16 08:07:49 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|