Java 如何记住一周中选定的几天及其值?

Java 如何记住一周中选定的几天及其值?,java,android,Java,Android,我正在创建一个android应用程序,它允许用户放置他的标签及其练习、设置和重复 我正在检索用户检查的一周中的几天,因此我想将这些天带到另一个活动。以下是步骤: 用户检查一周中的几天->新活动很快就会开始,它会要求您为您选择的每一天放置两个肌肉群 例如: 用户选择:星期一、星期二和星期六,下一步,星期一:横向和肩部;星期二:三头肌和二头肌;问题是我无法理解如何才能记住用户选择的日子。我试着得到一些算法,但从他选择的第一天起我就累了,我不知道如何增加它 Xml图像: 而不是&day1,应该是他

我正在创建一个android应用程序,它允许用户放置他的标签及其练习、设置和重复

我正在检索用户检查的一周中的几天,因此我想将这些天带到另一个活动。以下是步骤:

用户检查一周中的几天->新活动很快就会开始,它会要求您为您选择的每一天放置两个肌肉群

例如: 用户选择:星期一、星期二和星期六,下一步,星期一:横向和肩部;星期二:三头肌和二头肌;问题是我无法理解如何才能记住用户选择的日子。我试着得到一些算法,但从他选择的第一天起我就累了,我不知道如何增加它

Xml图像:

而不是&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();

    }


}
static Global g=new Global();
私有按钮nextconfig;
私人纺纱机gruppo1、gruppo2;
私有文本视图giorno;
字符串[]数组;
字符串[]数组two;
字符串ID选择喷丝头1,ID选择喷丝头2;
字符串id;
字符串名;
字符串[]天={“星期一”、“星期二”、“星期三”、“星期四”、“星期五”、“星期六”};
int[]daysBool;
int countClick=1;
int计数按钮;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_开始_2);
nextconfig=(按钮)findViewById(R.id.nextconfig);
gruppo1=(微调器)findviewbyd(R.id.gruppo1);
gruppo2=(微调器)findviewbyd(R.id.gruppo2);
giorno=(TextView)findViewById(R.id.giorno1);
Intent=getIntent();
int conta=intent.getIntExtra(“countButton”,0);
countButton=conta;
final SharedPreferences mPrefs=getSharedPreferences(“userInfo”,Context.MODE\u PRIVATE);
gruppo1.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){
idSelectedSpinner1=阵列两个[位置];
Log.d(“idSpinner:”,“+arrayTwo[position]);
}
@凌驾
未选择公共无效(AdapterView父级){
}
});
gruppo2.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){
idSelectedSpinner2=阵列两个[位置];
Log.d(“idSpinner:”,“+arrayTwo[position]);
}
@凌驾
未选择公共无效(AdapterView父级){
}
});
最后一个字符串url=g.getRootServer()+“/getMuscolarGroups.php”;
最终字符串urlDays=g.getRootServer()+“/getTab.php?token=“+mPrefs.getString”(“token”,null);
JsonObjectRequest myRequest=新JsonObjectRequest(Request.Method.GET,url,new JSONObject(),new Response.Listener()){
@凌驾
公共void onResponse(JSONObject响应){
Log.d(“RESPONSE”,RESPONSE.toString());
if(response.has(“errorCode”)){
试一试{
if(response.getInt(“errorCode”)==0){
JSONObject data=response.getJSONObject(“数据”);
JSONArray muscolarGroups=data.getJSONArray(“muscolarGroups”);
数组=新字符串[muscolarGroups.length()];
arrayTwo=新字符串[muscolarGroups.length()];

对于(int i=0;i我不会看你的代码片段,因为这就像让我为你做这项工作。相反,我会在一个非常高的层次上回答你,因为这确实是一个基本的droid,如果你在google上花费500万美元,你会找到很多关于这个主题的资料。 第一张图像的日期是您的“状态”,每天都可以选择或不选择,视图知道这一点。单击按钮后,您开始一个新活动:此时,将“状态”传递给新活动,并带有意图。另一方面,在创建的活动上,您将获得状态,并通过该信息填充您的活动使用选定的日期进行计划。
希望能有所帮助!

谢谢,伙计,我会努力的。顺便说一句,我只是问一个算法,而不是代码。不客气!要么你用错了“算法”这个词,要么我不明白你在问什么。在我看来,你想把所选的几天分配给其他活动,一旦它知道是哪几天,你就需要对它们进行迭代,并对每一天进行迭代有一个用户界面部分,允许用户做这做那。对吗?就像如果用户选择星期二和星期三,那么你的用户界面将有两天,如果用户选择所有天,那么你的用户界面将有7个条目(或者有7个提示,每天一个)。确切地说,我只需要下一个活动的这些天及其值,这样API就可以向数据库发送一个请求e memory group1&group2&dayNumber,即星期一=1,星期二=2等等。我想我的回答会帮助您:您的状态要么是选定的天,要么是一个类似{“星期一”,星期二}的列表,要么是一个带有选择的地图,如{星期一:已选中,星期二:已选中,星期三:未选中,星期四:未选中,星期五:未选中,星期六:未选中,星期日:未选中}。按照我的建议通过它,您就可以:)