Android应用程序中的Android View Pager问题

时间:2017-05-12 11:43:04

标签: android android-fragments android-viewpager android-tablayout

我在应用程序中使用View pager选项卡布局,然后动态加载数据,如果我点击Backpress按钮然后应用程序崩溃请给出解决方案。

 void Ugtwelveclassdata() {

    progressbar.setVisibility(View.VISIBLE);

    Map<String, String> params = new HashMap<String, String>();
    params.put("id", id);

    CustomRequest jsObjRequest = new CustomRequest(Request.Method.POST, url, params, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            Log.d("Volley", response.toString());
            progressbar.setVisibility(View.GONE);
            getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

            try {
                success12 = response.getString("success12");

                if (success12.equalsIgnoreCase("1")) {

                    // HIDE THE SPINNER AFTER LOADING FEEDS

                    progressbar.setVisibility(View.INVISIBLE);
                    Log.d("1", "I am in try block success is 12 class");

                    JSONObject primarydetailarray = response.getJSONObject("class12");


                    total_percent = primarydetailarray.getString(Constant.TOTAL_PERCENT);
                    Log.d("total_percent", total_percent);

                    overall_rank = primarydetailarray.getString(Constant.OVERALL_RANK);
                    Log.d("overall_rank", overall_rank);

                    term_first_overall = primarydetailarray.getString(Constant.TERM_FIRST_OVERALL);
                    Log.d("overall_rank", term_first_overall);

                    term_second_overall = primarydetailarray.getString(Constant.TERM_SECOND_OVERALL);
                    Log.d("overall_rank", term_second_overall);

                    term_first_rank = primarydetailarray.getString(Constant.TERM_FIRST_RANK);
                    Log.d("overall_rank", term_first_rank);

                    term_second_rank = primarydetailarray.getString(Constant.TERM_SECOND_RANK);
                    Log.d("overall_rank", term_second_rank);


                    marksheet = primarydetailarray.getString(Constant.MARKSHEET);
                    Log.d("marksheet", marksheet);

                    ug_subject_pkey = primarydetailarray.getString(Constant.UG_SUBJECT_PKEY);
                    Log.d("pg_subject_pkey", ug_subject_pkey);

                    term = primarydetailarray.getString(Constant.TERM);
                    Log.d("pg_subject_pkey", term);

                    marks = primarydetailarray.getString(Constant.MARKS);
                    Log.d("marks", marks);

                    approve = primarydetailarray.getString("approve_status");
                    Log.d("approve", approve);


                    if (user_type.equalsIgnoreCase("parent")) {
                        update.setVisibility(View.GONE);

                    } else {

                        update.setVisibility(View.VISIBLE);

                    }

                    if (approve.equalsIgnoreCase("1")) {

                        approvetv.setVisibility(View.VISIBLE);
                        notapprove.setVisibility(View.GONE);
                        browsebtn.setEnabled(false);
                        update.setVisibility(View.GONE);

                    } else {

                        approvetv.setVisibility(View.GONE);
                        notapprove.setVisibility(View.VISIBLE);
                        browsebtn.setEnabled(true);
                        update.setVisibility(View.VISIBLE);


                    }


                    subjectpkey = primarydetailarray.getString(Constant.SUBJECTPKEY);
                    Log.d("subjectpkey", subjectpkey);

                    acad_honour = primarydetailarray.getString(Constant.ACAD_HONOUR);
                    Log.d("acad_honour", acad_honour);


                    String getsubjectpky[] = subjectpkey.split(",");
                    System.out.println("getsubjectpky" + Arrays.toString(getsubjectpky));

                    String mark[] = marks.split(",");
                    System.out.println("mark" + Arrays.toString(mark));

                    String terms[] = term.split(",");
                    System.out.println("terms" + Arrays.toString(terms));


                    ugsubjectpk = ug_subject_pkey.split(",");
                    System.out.println("pkkkkkkkkkkkkkk" + Arrays.toString(ugsubjectpk));


                    for (int s = 0; s < getsubjectpky.length; s++) {


                        child = getLayoutInflater(null).inflate(R.layout.rownine, null);
                        mContainerView.addView(child);
                        markeltwelveclass = (EditText) child.findViewById(R.id.markgrade);
                        markeltwelveclass.setText(mark[s].trim());

                        termtwelveclass = (EditText) child.findViewById(R.id.termnine);
                        termtwelveclass.setText(terms[s].trim());

                        Button dltbtn = (Button) child.findViewById(R.id.deletesubject);
                        dltbtn.setVisibility(View.INVISIBLE);

                        if (getsubjectpky.length >= 4)

                        {
                            dltbtn.setVisibility(View.VISIBLE);
                        }


                        subjectspinner = (Spinner) child.findViewById(R.id.fragmentnine_edittext_subjectname);

                        subjectadapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, sub);
                        subjectadapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                        subjectspinner.setAdapter(subjectadapter);


                        for (int i = 0; i < subpkey.size(); i++) {

                            if (subpkey.get(i).equalsIgnoreCase(getsubjectpky[s])) {
                                subjectspinner.setSelection(i);
                            }
                        }


                        deletebtn = (Button) child.findViewById(R.id.deletesubject);
                        deletebtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {


                                {

                                    mContainerView.removeView((View) view.getParent());

                                }




                            }
                        });

                    }



                    if (subjectpkey.equalsIgnoreCase("0")) {

                        for (int p = 0; p < 2; p++) {
                            View child = getLayoutInflater(null).inflate(R.layout.rownine, null);
                            mContainerView.addView(child);

                            Button dltbtn = (Button) child.findViewById(R.id.deletesubject);
                            dltbtn.setVisibility(View.INVISIBLE);

                            subjectspinner = (Spinner) child.findViewById(R.id.fragmentnine_edittext_subjectname);

                            subjectadapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, sub);
                            subjectadapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                            subjectspinner.setAdapter(subjectadapter);
                        }
                    }


                    twtotalpercentage.setText(total_percent);
                    twoverallrank.setText(overall_rank);
                    twaccademichonours.setText(acad_honour);
                    twfilename.setText(marksheet);
                    twtermoneovr.setText(term_first_overall);
                    twtermonerank.setText(term_first_rank);
                    twtermtwoovr.setText(term_second_overall);
                    twtermtworank.setText(term_second_rank);


                    if (twfilename.getText().toString().equalsIgnoreCase("null")) {

                        twfilename.setText("");

                    }


                } else {


                    update.setText("Submit");

                    progressbar.setVisibility(View.INVISIBLE);

                    for (int p = 0; p < 3; p++) {
                        View child = getLayoutInflater(null).inflate(R.layout.rownine, null);
                        mContainerView.addView(child);

                        Button dltbtn = (Button) child.findViewById(R.id.deletesubject);
                        dltbtn.setVisibility(View.INVISIBLE);


                        subjectspinner = (Spinner) child.findViewById(R.id.fragmentnine_edittext_subjectname);

                        subjectadapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, sub);
                        subjectadapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                        subjectspinner.setAdapter(subjectadapter);
                    }
                    Log.d("fail", "status fail");
                }

            } catch (Exception e) {
                e.printStackTrace();
                showToast("Something embarrassing happened here.");
            }

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
            VolleyLog.d("Volley", "Error: " + error.getMessage());
            showToast("Connection Error");
            progressbar.setVisibility(View.GONE);
            getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
        }


    });

    //requestQueue.add(jsObjRequest);
    // Adding request to request queue

    jsObjRequest.setRetryPolicy(new DefaultRetryPolicy(
            30000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    AppController.getInstance().addToRequestQueue(jsObjRequest);
}

片段代码

NSOpenPanel *panel = [NSOpenPanel openPanel];
if ([panel runModal] == NSFileHandlingPanelOKButton) {        

    albumURL = [panel URL];
    info = [NSString stringWithContentsOfURL: albumURL encoding: NSASCIIStringEncoding error: NULL];
    listItems = [info componentsSeparatedByString:@"\n"];        
    NSString *combinedString = [listItems componentsJoinedByString:@"\n"];

    //[self.TrackList setValue:combinedString forKey: combinedString];
}

0 个答案:

没有答案