|
|
|
Android รบกวนด้วยครับ พอกดปุ่มบันทึก แล้ว text บนปุ่มบันทึกมันหาย มี code |
|
|
|
|
|
|
|
รบกวนดู code ให้หน่อยครับ
พอกดปุ่มบันทึก แล้ว text บนปุ่มบันทึกมันหาย(ถูก Clear) ไปพร้อมกับตัวอื่นด้วย แก้ตรงไหนครับ
Code (Java)
Code ::
public class RecordActivity extends AppCompatActivity {
Spinner spinnerListMonth,spinnerArea,spinnerMoo;
EditText txtYear,txtMeterNo,txtFullName,txtAddress,txtStatus,txtBuildType,txtSearch,txtRecord;
RadioButton radMeter,radHouseId;
Button btnSave;
int reqId=0;
Calendar calendar;
int selectMonth;
SharedPreferences sharedPreferences;
SharedPreferences.Editor editor;
int iStatusImport=1;
int iStatusChangeMonth = 0;
boolean HouseCheck = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_record);
sharedPreferences = getSharedPreferences("MyPref",MODE_PRIVATE);
editor = sharedPreferences.edit();
txtMeterNo = (EditText)findViewById(R.id.txtMeterNo);
txtFullName = (EditText)findViewById(R.id.txtFullName);
txtAddress = (EditText)findViewById(R.id.txtAddress);
txtStatus = (EditText)findViewById(R.id.txtStatus);
txtBuildType = (EditText)findViewById(R.id.txtBuildType);
txtSearch = (EditText)findViewById(R.id.txtSearch);
txtSearch.setInputType(InputType.TYPE_CLASS_DATETIME);
txtSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
clearValueForm();
}
}
});
txtRecord = (EditText)findViewById(R.id.txtRecord);
radHouseId = (RadioButton)findViewById(R.id.radHouseId);
radHouseId.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked==false){
txtSearch.setHint(getResources().getString(R.string.text_meter));
clearValueForm();
}}
});
radMeter = (RadioButton)findViewById(R.id.radMeter);
radMeter.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked==false){
txtSearch.setHint(getResources().getString(R.string.text_home));
clearValueForm();
}}
});
spinnerArea = (Spinner)findViewById(R.id.spinnerArea);
spinnerMoo = (Spinner)findViewById(R.id.spinnerMoo);
spinnerListMonth = (Spinner)findViewById(R.id.spinnerMonth);
spinnerListMonth.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectMonth = position+1;
iStatusChangeMonth++;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
calendar = Calendar.getInstance();
btnSave = (Button)findViewById(R.id.btnSave);
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (txtRecord.getText().length() != 0 && reqId != 0) {
if(iStatusChangeMonth==1) {
AlertDialog.Builder alert = new AlertDialog.Builder(RecordActivity.this);
alert.setTitle("Confirm");
alert.setMessage("คุณต้องการใช้เดือน : " + spinnerListMonth.getSelectedItem().toString());
alert.setPositiveButton("ยืนยัน", new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
saveValueMeter();
}
});
alert.setNegativeButton("ยกเลิก", null);
alert.show();
}else{
saveValueMeter();
}
} else {
new Msg().msg(getApplicationContext(), "กรุณากรอกเลขมิเตอร์");
return;
}
}
});
txtSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (iStatusImport == 0) {
return;
}
getDataForRecord(txtSearch.getText().toString());
}
@Override
public void afterTextChanged(Editable s) {
}
});
spinnerArea.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
getListMoo(spinnerArea.getSelectedItem().toString());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
Button btnExit = (Button)findViewById(R.id.btnExit);
btnExit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
loadListMonth();
getYear();
getListTambon();
}
private void saveValueMeter(){
int meterYear = calendar.get(Calendar.YEAR)+543;
int meterMonth = selectMonth;
int meterValue = Integer.parseInt(txtRecord.getText().toString().trim());
String meterDate ="";
meterDate+=Integer.toString(calendar.get(Calendar.YEAR));
meterDate+="-";
meterDate+=Integer.toString(calendar.get(Calendar.MONTH)+1);
meterDate+="-";
meterDate+=Integer.toString(calendar.get(Calendar.DATE));
meterDate+=" ";
meterDate+=Integer.toString(calendar.get(Calendar.HOUR_OF_DAY));
meterDate+=":";
meterDate+=Integer.toString(calendar.get(Calendar.MINUTE));
meterDate+=":";
meterDate+=Integer.toString(calendar.get(Calendar.SECOND));
int meterUserId=sharedPreferences.getInt("user",0);
dbHelper dbHelper = new dbHelper(this);
int statusInsert=(int)dbHelper.insertValueMonth(reqId,meterYear,meterMonth,meterValue,meterDate,meterUserId);
if(statusInsert!=-1){
new Msg().msg(getApplicationContext(),"บันทึกข้อมูลเรียบร้อยแล้ว");
clearValueForm();
}else{
new Msg().msg(getApplicationContext(),"ไม่สามารถบันทึกข้อมูลได้");
}
}
private void loadListMonth(){
ArrayAdapter<String> spinnerMonthAdapter;
dbHelper dbHelper = new dbHelper(this);
List<String> listMonth = dbHelper.getListMonth();
spinnerMonthAdapter = new ArrayAdapter<String>(RecordActivity.this,android.R.layout.simple_dropdown_item_1line,listMonth);
spinnerListMonth.setAdapter(spinnerMonthAdapter);
}
private void getYear(){
txtYear = (EditText)findViewById(R.id.txtYear);
Calendar c = Calendar.getInstance();
int iYear = c.get(Calendar.YEAR)+543;
String iStrYear = Integer.toString(iYear);
txtYear.setText(iStrYear);
txtYear.setEnabled(false);
}
private void clearValueForm(){
txtMeterNo.setText("");
txtFullName.setText("");
txtAddress.setText("");
txtStatus.setText("");
txtBuildType.setText("");
txtRecord.setText("");
txtSearch.setText("");
reqId=0;
txtSearch.requestFocus();
}
private void getDataForRecord(String iFindValue){
dbHelper dbHelper = new dbHelper(this);
int fType=0;
// fType = Type of search (0=Find HouseID,1=Find MeterNo)
if(radMeter.isChecked()){
fType=1;
}else{
fType=0;
}
String strMooName = spinnerMoo.getSelectedItem().toString();
String strTambonName = spinnerArea.getSelectedItem().toString();
String[] iDataFromDB = dbHelper.findDataForRecord(iFindValue,strTambonName,strMooName,fType);
// Title_Name+","+//0
// Meter_No + ","+//1
// Other_Detail+","+//2
// Req_ID+","+//3
// Requester_Name+","+//4
// Requester_Surname+","+//5
// Requester_Addr+","+//6
// Requester_Road+","+//7
// Requester_Soi+","+//8
// Requester_Moo+","+//9
// Requester_Tambon+","+//10
// Requester_Amphur+","+//11
// Requester_Province+","+//12
// Building_Type_Desc+"//13
if(iDataFromDB!=null) {
txtStatus.setText(iDataFromDB[2].toString());
txtStatus.setEnabled(false);
txtFullName.setText(iDataFromDB[0].toString() + iDataFromDB[4].toString() + " " + iDataFromDB[5].toString());
txtFullName.setEnabled(false);
txtMeterNo.setText(iDataFromDB[1].toString());
txtMeterNo.setEnabled(false);
txtBuildType.setText(iDataFromDB[13].toString());
txtBuildType.setEnabled(false);
String iAddress = "";
iAddress += iDataFromDB[6].toString() + " ";
if (iDataFromDB[7].length() != 0) {
iAddress += "ถนน" + iDataFromDB[7].toString() + " ";
}
if (iDataFromDB[8].length() != 0) {
iAddress += "ซอย" + iDataFromDB[8].toString() + " ";
}
if (iDataFromDB[9].length() != 0) {
iAddress += "หมู่ " + iDataFromDB[9].toString() + " ";
}
if (iDataFromDB[10].length() != 0) {
iAddress += "ตำบล" + iDataFromDB[10].toString();
}
txtAddress.setText(iAddress);
txtAddress.setEnabled(false);
reqId=Integer.parseInt(iDataFromDB[3]);
}
//else{
// new Msg().msg(getApplicationContext(),"Cannot find");
//}
}
private void getListTambon(){
dbHelper dbHelper = new dbHelper(this);
ArrayAdapter<String> spinnerTambonAdapter;
List<String> listTambon = dbHelper.getListTambon();
if(listTambon==null){
new Msg().msg(getApplicationContext(),"กรุณาทำการ Import ข้อมูลก่อน");
iStatusImport=0;
return;
}
spinnerTambonAdapter = new ArrayAdapter<String>(RecordActivity.this,android.R.layout.simple_dropdown_item_1line,listTambon);
spinnerArea.setAdapter(spinnerTambonAdapter);
}
private void getListMoo(String sTrtambon){
dbHelper dbHelper = new dbHelper(this);
ArrayAdapter<String> spinnerMooAdapter;
List<String> listMoo = dbHelper.getListMoo(sTrtambon);
spinnerMooAdapter = new ArrayAdapter<String>(RecordActivity.this,android.R.layout.simple_dropdown_item_1line,listMoo);
spinnerMoo.setAdapter(spinnerMooAdapter);
}
}
Tag : Java, Android, Mobile
|
ประวัติการแก้ไข 2016-06-12 09:42:38 2016-06-12 16:18:55
|
|
|
|
|
Date :
2016-06-12 09:37:36 |
By :
veest99 |
View :
1668 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|