警报对话框 - 如何?

时间:2018-03-19 11:44:32

标签: android android-layout android-fragments android-asynctask

在我的项目中。我正在使用两个警报对话框。私人方法中使用的两个警报对话框。私有方法为checkIn( )checkOut( )

在主要活动中,我有一个按钮。 Button的两个功能。一个功能是签到,另一个功能是签出。

当我在登记入住活动时,按钮可见。如果我单击按钮。它将更改为签出并显示警报对话checkIn( )私有方法。

如果我刷新活动它将变为登记入住。 当我刷新活动时,我的问题是如何获得Checkout Action。任何人都可以解决并为此提供解决方案......

提前谢谢你。我附上了以下示例代码

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();
        }
    }

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

定义这些变量:

<base href="{{CDN-PATH-HARE}}">

并添加这些方法:

webpack

并更新您的代码:

    public static final String PREF_FLAG = "FLAG";
    private static String COUT = "cout";
    private static String CIN = "cin";
    private static String defaultFlagValue = COUT;

最后更新游览 private String getFlag() { return sharedPreferences.getString(PREF_FLAG, defaultFlagValue); } private void setFlag(String flag) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(PREF_FLAG, flag); editor.apply(); } 功能

private void CheckinButton() {
        if (getFlag() == COUT) {

            ...

            setFlag(CIN);
        }

    }

private void CheckoutButton() {
        if (getFlag() == CIN) {

            ...

            setFlag(COUT);
        }
    }

希望它会有所帮助