我怎么能记住一周中选定的几天及其价值?

时间:2017-06-29 08:18:54

标签: java android

我正在创建一个Android应用程序,允许用户放置他的标签及其练习,设置和代表。

我正在检索用户检查的一周中的日期,所以我想把这些日子带到另一个活动中。这是一步:

用户检查本周的日子 - >新的活动是开放的,它会要求你在每天选择两个MUSCOLAR组。

实施例: 用户选择:星期一,星期二和星期六,下一步,星期一:拉特和肩膀;星期二:肱三头肌和肱二头肌;问题是我无法理解如何记住用户选择的日子。我尝试了一些算法,但我在他选择的第一天就堆叠了,我不知道如何增加它。

Xml图片:

First step

Second step

而不是& day1,应该有他逐一检查的日子。

Java源代码:

 static Global g = new Global();
private Button nextconfig;
private Spinner gruppo1,gruppo2;
private TextView giorno;
String[] array ;
String [] arrayTwo;
String idSelectedSpinner1, idSelectedSpinner2;
String id;
String name;
String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

int[] daysBool;
int countClick=1;
int countButton;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_starting_2);
    nextconfig = (Button) findViewById(R.id.nextconfig);
    gruppo1=(Spinner) findViewById(R.id.gruppo1);
    gruppo2=(Spinner) findViewById(R.id.gruppo2);
    giorno=(TextView) findViewById(R.id.giorno1);

    Intent intent = getIntent();
    int conta=intent.getIntExtra("countButton",0);
    countButton=conta;

    final SharedPreferences mPrefs = getSharedPreferences("userInfo", Context.MODE_PRIVATE);

    gruppo1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            idSelectedSpinner1=arrayTwo[position];
            Log.d("idSpinner:","" + arrayTwo[position]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    gruppo2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            idSelectedSpinner2=arrayTwo[position];
            Log.d("idSpinner:","" + arrayTwo[position]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });



    final String url = g.getRootServer() + "/getMuscolarGroups.php";
    final String urlDays = g.getRootServer() + "/getTab.php?token="+mPrefs.getString("token",null);



    JsonObjectRequest myRequest = new JsonObjectRequest(Request.Method.GET, url, new JSONObject(), new Response.Listener<JSONObject>() {

        @Override
            public void onResponse(JSONObject response) {
                Log.d("RESPONSE", response.toString());

                if (response.has("errorCode")) {
                    try {

                        if (response.getInt("errorCode") == 0) {
                            JSONObject data = response.getJSONObject("data");
                            JSONArray muscolarGroups = data.getJSONArray("muscolarGroups");
                            array= new String [muscolarGroups.length()];
                            arrayTwo= new String [muscolarGroups.length()];
                            for (int i=0;i<muscolarGroups.length();i++){

                                JSONObject muscolarData = muscolarGroups.getJSONObject(i);
                                id = muscolarData.getString("id");
                                name = muscolarData.getString("name");

                                array[i]=name;
                                arrayTwo[i]=id;
                            }

                            addToSpinner(array);
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                }
            }) {
        };

        MySingleton.getInstance(getBaseContext()).addToRequestQueue(myRequest);
        Log.d("REQUEST", myRequest.toString());



    JsonObjectRequest myRequestDays = new JsonObjectRequest(Request.Method.GET, urlDays, new JSONObject(), new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            Log.d("RESPONSE", response.toString());

            if (response.has("errorCode")) {
                Log.d("response","" + response);
                try {

                    if (response.getInt("errorCode") == 0) {
                        JSONObject data = response.getJSONObject("data");
                        JSONObject tab = data.getJSONObject("tab");
                        daysBool = new int[tab.length() -1];
                        int monday = tab.getInt("monday");
                        int tuesday = tab.getInt("tuesday");
                        int wednesday = tab.getInt("wednesday");
                        int thursday = tab.getInt("thursday");
                        int friday = tab.getInt("friday");
                        int saturday = tab.getInt("saturday");

                        Log.d("Saturday", " "+saturday);

                        daysBool[0] = monday;
                        daysBool[1] = tuesday;
                        daysBool[2] = wednesday;
                        daysBool[3] = thursday;
                        daysBool[4] = friday;
                        daysBool[5] = saturday;

                        if (monday == 1) {
                            giorno.setText(days[0]);
                        } else if (tuesday == 1) {
                            giorno.setText(days[1]);
                        } else if (wednesday == 1) {
                            giorno.setText(days[2]);
                        } else if (thursday == 1) {
                            giorno.setText(days[3]);
                        }else if (friday == 1) {
                            giorno.setText(days[4]);
                        }else if (saturday == 1) {
                            giorno.setText(days[5]);
                        }


                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    }) {


    };

    MySingleton.getInstance(getBaseContext()).addToRequestQueue(myRequestDays);
    Log.d("REQUEST", myRequestDays.toString());




        nextconfig.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {



                String url = g.getRootServer() + "/setTabGroup.php?token=" + mPrefs.getString("token",null) + "&groupOneId=" + idSelectedSpinner1 + "&groupTwoId=" + idSelectedSpinner2 +"&dayNumber=3";
                final Map<String, String> params = new HashMap<>();
                //Parametri
                params.put("token","token"+mPrefs.getString("token",null));
                params.put("groupOneId","groupOneId"+idSelectedSpinner1);
                params.put("groupTwoId","groupTwoId" +idSelectedSpinner2);
                params.put("dayNumber","dayNumber" +idSelectedSpinner2);

                JsonObjectRequest myRequest = new JsonObjectRequest(Request.Method.GET, url, new JSONObject(params), new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d("RESPONSE", response.toString());

                        if (response.has("errorCode"))
                        {
                            try {


                                if (response.getInt("errorCode") == 0) {


                                    if (countClick==countButton){
                                        Intent intent = new Intent(getBaseContext(), Gruppo.class);
                                        intent.putExtra("daysTab",days);
                                        intent.putExtra("daysTabBool",daysBool);
                                        startActivity(intent);
                                        finish();
                                    }
                                    countClick++;

                                }
                            }  catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }

                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {

                        }
                    }) {
                    };

                MySingleton.getInstance(getBaseContext()).addToRequestQueue(myRequest);
                Log.d("REQUEST", myRequest.toString());
                }
            });
    }

    void getDays() {






    }


    void addToSpinner(String[] array) {
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.spinner_item, array);
        gruppo1.setAdapter(adapter);
        gruppo2.setAdapter(adapter);


        }


        @Override
        public void onBackPressed() {

            Intent intent = new Intent(getBaseContext(), TabStarting.class);
            startActivity(intent);
            finish();

    }


}

1 个答案:

答案 0 :(得分:0)

我不会看你的代码片段,因为这就像是让我为你做的工作。相反,我会在很高的层次上回答你,因为这是非常基本的机器人,如果你在谷歌上花费5米,你会发现很多关于这个话题的材料。 您的第一张图片的日期是您的“状态”,每天都可以选择或不选择,并且视图知道这一点。单击该按钮后,您将启动一个新活动:此时,将“状态”传递给具有意图的新活动。另一方面,在创建的活动中,您将获得州,并且通过该信息,您将使用所选日期填充您的日程安排。 希望它有所帮助!