【发布时间】:2018-08-27 23:11:10
【问题描述】:
在我的项目中。我正在使用两个警报对话框。私有方法中使用的两个警报对话框。私有方法是checkIn( ) 和checkOut( )
在主要活动中,我有一个按钮。按钮的两个功能。一个功能是签入,另一个功能是签出。
当我进入 Activity 时,按钮在 Check-in 中可见。如果我单击按钮。它变为 Check out 并显示 Alert Dialogue checkIn( ) 私有方法。
如果我刷新 Activity 它将变为签入。 当我刷新活动时,我的问题是如何获得结帐操作。任何人都可以解决并为此提供解决方案...
提前谢谢你。我附上了下面的示例代码
public class Insert_DataSql extends AppCompatActivity {
private long UPDATE_INTERVAL = 2 * 1000; /* 10 secs */
private long FASTEST_INTERVAL = 2000; /* 2 sec */
LocationRequest locationRequest;
LocationManager locationManager;
PreparedStatement preparedStatement;
String formattedDate;
WebConnection connectionClass;
Button cin,cout;
TextView dat,tim,adddre;
Boolean flag=true;
SharedPreferences sharedPreferences;
String username;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_insertdata);
connectionClass = new WebConnection();
sharedPreferences=getSharedPreferences("LoginPref", Context.MODE_PRIVATE);//here we go getdata
user name=sharedPreferences.getString("User name",null);
//Button Click able
cin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
buildAlertMessageNoGps();
} else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
if (flag) {
getMyCurrentLocation();
CheckinButton();
flag =false;
Toast.makeText(Insert_DataSql.this, "True statement", Toast.LENGTH_SHORT).show();
dat.setText(date);
new Insert_data().execute("");//insert for button
// tim.setText(formattedDate);
}
else{
flag =true;
getMyCurrentLocation();
CheckoutButton();
Toast.makeText(Insert_DataSql.this, "Wrong statement", Toast.LENGTH_SHORT).show();
dat.setText(date);
new Insert_data().execute("");
// tim.setText(formattedDate);
}
}
}
//警报对话框的私有方法
private void CheckoutButton() {
if(flag == false ){
cin .setText("Check Out Sucessfull");
AlertDialog alertDialog = new AlertDialog.Builder(
Insert_DataSql.this).create();
alertDialog.setTitle("Check Out Sucessfully");
alertDialog.setMessage(adddre.getText());
alertDialog.setIcon(R.drawable.ic_access_time_black_24dp);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
}
});
alertDialog.show();
}
}
private void CheckinButton() {
if(flag == true ){
cin.setText("Check Out");
AlertDialog alertDialog = new AlertDialog.Builder(
Insert_DataSql.this).create();
alertDialog.setTitle("Check In Sucessfully");
alertDialog.setMessage("Have A Nice Day");
alertDialog.setIcon(R.drawable.ic_access_time_black_24dp);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
}
});
alertDialog.show();
}
}
【问题讨论】:
标签: android android-layout android-fragments android-asynctask