当我在android中请求超过4次时,Asp.Net服务不会返回响应消息

时间:2014-08-18 10:57:00

标签: android asp.net web-services parsing android-parser

我正在制作Android应用程序,我正在解析来自Asp.NET服务的数据。当我调用服务超过4次它没有返回响应时,我没有从中获取数据并等待大约10分钟服务工作我可以从中获取数据。我正在尝试2周,但我没有解决它。请帮帮我..代码如下

public class SonrakiActivity extends Activity {

Bundle get_data;
int bas_i;
TextView txt, text2;

// Button secretbtn;

String Type;
int TypeID;
int GrpID;
int id;

int sorusayisi = 0;
int cevaplanan = 0;
boolean hata = false;

int akis_soru_sorusayisi = 0;

String last_Type_inmethod;

Bundle data_gonder;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sonraki_olay);

    txt = (TextView) findViewById(R.id.textView1);



    get_data = getIntent().getExtras();
    bas_i = get_data.getInt("data_sonraki_soru_id");


    data_gonder = new Bundle();

    gonder();

}

public void gonder() {

    try {
        new Thread(new Runnable() {
            @Override
            public void run() {

                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(
                        "http://78.186.62.169:8210/AnketServis.asmx/Question");

                httppost.setHeader("Content-type", "application/json");
                httppost.setHeader("Accept", "application/json");

                JSONObject jsonparameter = new JSONObject();

                final GlobalClass globalVariable_soru = (GlobalClass) getApplicationContext();

                try {

                    int type_id = Akis_TypeID();
                    int grp_id = Akis_GrpID();

                    Log.i("Akis_TypeID()", "" + type_id);
                    Log.i("Akis_GrpID()", "" + grp_id);

                    jsonparameter.put("ID", type_id);
                    jsonparameter.put("GrpID", grp_id);

                    httppost.setEntity(new StringEntity(jsonparameter
                            .toString(), "UTF-8"));

                    Log.i("httppost", "" + httppost);

                    HttpResponse response = httpclient.execute(httppost);

                    HttpEntity entity = response.getEntity();

                    String responseText = EntityUtils.toString(entity);
                    Log.i("@responceQuestion_Soru", "" + responseText);

                    try {
                        JSONObject returndata = new JSONObject(responseText);
                        JSONArray jsonMainNode = returndata
                                .optJSONArray("d");
                        int lengthJsonArr = jsonMainNode.length();
                        Log.i("@lengthJsonQuestion_Soru", ""
                                + lengthJsonArr);
                        sorusayisi = lengthJsonArr;

                        // Quetion_ID
                        final int question_id = Akis_TypeID();
                        Log.i("Question_id_Soru", "" + question_id);

                        for (int i = 0; i < sorusayisi; i++) {

                            if (i == sorusayisi)
                                break;
                            JSONObject jsonChildNode = jsonMainNode
                                    .getJSONObject(i);

                            try {

                                final String Text = jsonChildNode
                                        .optString("Text");

                                globalVariable_soru.setSorumuz(Text);

                                Log.i("Log_banner_Text", "" + Text);

                                final int cevap_id = jsonChildNode
                                        .optInt("CevapID");

                                final List<String> answer = Cevaplar(cevap_id);

                                Log.i("Answers", "" + answer);

                                Log.i("Log_banner_ID", "" + cevap_id);

                                final int cevap_sayisi = jsonChildNode
                                        .optInt("CevapSayisi");

                                Log.i("Log_cevap_sayisi", "" + cevap_sayisi);

                                if (i == 0) {
                                    txt.post(new Runnable() {
                                        @Override
                                        public void run() {
                                            try {

                                                final RelativeLayout lm = (RelativeLayout) findViewById(R.id.genelLayout);

                                                txt.setText(Text);

                                                if (cevap_sayisi == 2) {

                                                    Button btn1 = new Button(
                                                            getApplicationContext());
                                                    btn1.setBackgroundResource(R.drawable.stylebutton_iyi);
                                                    btn1.setText(answer
                                                            .get(0));
                                                    btn1.setTextSize(30);
                                                    btn1.setTextColor(Color.BLACK);
                                                    btn1.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(1,
                                                                    question_id);

                                                        }

                                                    });

                                                    Button btn2 = new Button(
                                                            getApplicationContext());
                                                    btn2.setBackgroundResource(R.drawable.stylebutton_orta);
                                                    btn2.setText(answer
                                                            .get(1));
                                                    btn2.setTextSize(30);
                                                    btn2.setTextColor(Color.BLACK);
                                                    btn2.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(2,
                                                                    question_id);

                                                        }

                                                    });

                                                    LinearLayout ll = (LinearLayout) findViewById(R.id.buttonlayout);

                                                    ll.setOrientation(LinearLayout.VERTICAL);
                                                    LayoutParams lp = new LayoutParams(
                                                            new LayoutParams(
                                                                    300,
                                                                    100));

                                                    ll.addView(btn1, lp);
                                                    ll.addView(btn2, lp);
                                                    lm.addView(ll);

                                                }

                                                if (cevap_sayisi == 3) {

                                                    Button btn1 = new Button(
                                                            getApplicationContext());
                                                    btn1.setText(answer
                                                            .get(0));
                                                    btn1.setBackgroundResource(R.drawable.stylebutton_iyi);
                                                    btn1.setTextSize(30);
                                                    btn1.setTextColor(Color.BLACK);
                                                    btn1.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(1,
                                                                    question_id);
                                                            // Intent inm =
                                                            // new
                                                            // Intent(getApplicationContext(),BitisMesage.class);
                                                            // startActivity(inm);

                                                        }

                                                    });

                                                    Button btn2 = new Button(
                                                            getApplicationContext());
                                                    btn2.setText(answer
                                                            .get(1));
                                                    btn2.setBackgroundResource(R.drawable.stylebutton_orta);
                                                    btn2.setTextSize(30);
                                                    btn2.setTextColor(Color.BLACK);
                                                    btn2.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(2,
                                                                    question_id);

                                                        }

                                                    });

                                                    Button btn3 = new Button(
                                                            getApplicationContext());
                                                    btn3.setText(answer
                                                            .get(2));
                                                    btn3.setBackgroundResource(R.drawable.stylebutton_kotu);
                                                    btn3.setTextSize(30);
                                                    btn3.setTextColor(Color.BLACK);
                                                    btn3.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(3,
                                                                    question_id);

                                                        }

                                                    });

                                                    LinearLayout ll = (LinearLayout) findViewById(R.id.buttonlayout);
                                                    ll.setOrientation(LinearLayout.VERTICAL);
                                                    LayoutParams lp = new LayoutParams(
                                                            new LayoutParams(
                                                                    300,
                                                                    100));

                                                    ll.addView(btn1, lp);
                                                    ll.addView(btn2, lp);
                                                    ll.addView(btn3, lp);
                                                    lm.addView(ll);

                                                }

                                                if (cevap_sayisi == 4) {

                                                    Button btn1 = new Button(
                                                            getApplicationContext());
                                                    btn1.setText(answer
                                                            .get(0));
                                                    btn1.setBackgroundResource(R.drawable.stylebutton_iyi);
                                                    btn1.setTextSize(30);
                                                    btn1.setTextColor(Color.BLACK);
                                                    btn1.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(1,
                                                                    question_id);

                                                        }

                                                    });

                                                    Button btn2 = new Button(
                                                            getApplicationContext());
                                                    btn2.setText(answer
                                                            .get(1));
                                                    btn2.setBackgroundResource(R.drawable.stylebutton_orta);
                                                    btn2.setTextSize(30);
                                                    btn2.setTextColor(Color.BLACK);
                                                    btn2.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(2,
                                                                    question_id);

                                                        }

                                                    });

                                                    Button btn3 = new Button(
                                                            getApplicationContext());
                                                    btn3.setText(answer
                                                            .get(2));
                                                    btn3.setBackgroundResource(R.drawable.stylebutton_kotu);
                                                    btn3.setTextSize(30);
                                                    btn3.setTextColor(Color.BLACK);
                                                    btn3.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(3,
                                                                    question_id);

                                                        }
                                                    });

                                                    Button btn4 = new Button(
                                                            getApplicationContext());
                                                    btn4.setText(answer
                                                            .get(3));
                                                    btn4.setBackgroundResource(R.drawable.stylebutton_fena);
                                                    btn4.setTextSize(30);
                                                    btn4.setTextColor(Color.BLACK);
                                                    btn4.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub
                                                            Cevapla(4,
                                                                    question_id);

                                                        }
                                                    });

                                                    LinearLayout ll = (LinearLayout) findViewById(R.id.buttonlayout);
                                                    ll.setOrientation(LinearLayout.VERTICAL);
                                                    LayoutParams lp = new LayoutParams(
                                                            new LayoutParams(
                                                                    300,
                                                                    100));

                                                    ll.addView(btn1, lp);
                                                    ll.addView(btn2, lp);
                                                    ll.addView(btn3, lp);
                                                    ll.addView(btn4, lp);
                                                    lm.addView(ll);

                                                }

                                                if (cevap_sayisi == 5) {

                                                    Button btn1 = new Button(
                                                            getApplicationContext());
                                                    btn1.setText(answer
                                                            .get(0));
                                                    btn1.setBackgroundResource(R.drawable.stylebutton_iyi);
                                                    btn1.setTextSize(30);
                                                    btn1.setTextColor(Color.BLACK);
                                                    btn1.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(1,
                                                                    question_id);

                                                        }

                                                    });

                                                    Button btn2 = new Button(
                                                            getApplicationContext());
                                                    btn2.setText(answer
                                                            .get(1));
                                                    btn2.setBackgroundResource(R.drawable.stylebutton_orta);
                                                    btn2.setTextSize(30);
                                                    btn2.setTextColor(Color.BLACK);
                                                    btn2.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(2,
                                                                    question_id);

                                                        }

                                                    });

                                                    Button btn3 = new Button(
                                                            getApplicationContext());
                                                    btn3.setText(answer
                                                            .get(2));
                                                    btn3.setBackgroundResource(R.drawable.stylebutton_kotu);
                                                    btn3.setTextSize(30);
                                                    btn3.setTextColor(Color.BLACK);
                                                    btn3.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(3,
                                                                    question_id);

                                                        }

                                                    });

                                                    Button btn4 = new Button(
                                                            getApplicationContext());
                                                    btn4.setText(answer
                                                            .get(3));
                                                    btn4.setBackgroundResource(R.drawable.stylebutton_fena);
                                                    btn4.setTextSize(30);
                                                    btn4.setTextColor(Color.BLACK);
                                                    btn4.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(4,
                                                                    question_id);

                                                        }

                                                    });

                                                    Button btn5 = new Button(
                                                            getApplicationContext());
                                                    btn5.setText(answer
                                                            .get(4));
                                                    btn5.setBackgroundResource(R.drawable.stylebutton_cokiyi);
                                                    btn5.setTextSize(30);
                                                    btn5.setTextColor(Color.BLACK);
                                                    btn5.setOnClickListener(new OnClickListener() {

                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            // TODO
                                                            // Auto-generated
                                                            // method stub

                                                            Cevapla(5,
                                                                    question_id);

                                                        }

                                                    });

                                                    LinearLayout ll = (LinearLayout) findViewById(R.id.buttonlayout);
                                                    ll.setOrientation(LinearLayout.VERTICAL);
                                                    LayoutParams lp = new LayoutParams(
                                                            new LayoutParams(
                                                                    300,
                                                                    100));

                                                    ll.addView(btn1, lp);
                                                    ll.addView(btn2, lp);
                                                    ll.addView(btn3, lp);
                                                    ll.addView(btn4, lp);
                                                    ll.addView(btn5, lp);
                                                    lm.addView(ll);

                                                }

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

                                            }

                                        }
                                    });

                                }

                            } catch (Exception e) {

                                Onceki_soru();
                            }
                        }

                    } catch (JSONException e) {
                        Onceki_soru();

                    }

                } catch (Exception e) {

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(),
                                    "İnternet ayarlarınızı kontrol ediniz",
                                    Toast.LENGTH_SHORT).show();
                        }
                    });

                    Onceki_soru();
                    e.printStackTrace();
                }
            }

        }).start();

    }

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

}

private List<String> Cevaplar(int cevabim_id) {

    List<String> getCevap = new ArrayList<String>();

    try {

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "http://78.186.62.169:8210/AnketServis.asmx/Answers");

        httppost.setHeader("Content-type", "application/json");
        httppost.setHeader("Accept", "application/json");

        JSONObject jsonparameter = new JSONObject();
        jsonparameter.put("ID", cevabim_id);

        httppost.setEntity(new StringEntity(jsonparameter.toString(),
                "UTF-8"));

        Log.i("httppost", "" + httppost);

        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        String responseText = EntityUtils.toString(entity);
        Log.i("@responceAnswers", "" + responseText);

        try {

            JSONObject returndata = new JSONObject(responseText);
            JSONArray jsonMainNode = returndata.optJSONArray("d");
            int lengthJsonArr = jsonMainNode.length();
            Log.i("@lengthJsonAnswer", "" + lengthJsonArr);
            sorusayisi = lengthJsonArr;

            for (int i = 0; i < sorusayisi; i++) {

                if (i == sorusayisi)
                    break;
                JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);

                try {
                    final String value1 = jsonChildNode.optString("Value1");
                    final String value2 = jsonChildNode.optString("Value2");
                    final String value3 = jsonChildNode.optString("Value3");
                    final String value4 = jsonChildNode.optString("Value4");
                    final String value5 = jsonChildNode.optString("Value5");

                    getCevap.add(value1);
                    getCevap.add(value2);
                    getCevap.add(value3);
                    getCevap.add(value4);
                    getCevap.add(value5);

                } catch (Exception e) {
                    // TODO: handle exception
                }
            }

        } catch (Exception e) {
            // TODO: handle exception

        }

    } catch (Exception e) {
        // TODO: handle exception

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getApplicationContext(),
                        "İnternet ayarlarınızı kontrol ediniz",
                        Toast.LENGTH_SHORT).show();
            }
        });
    }
    return getCevap;

    // TODO Auto-generated method stub

}

private int Akis_TypeID() {
    try {

        JSONObject returndata = null;
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "http://78.186.62.169:8210/AnketServis.asmx/Akis");
        httppost.setHeader("Content-type", "application/json");
        JSONObject jsonparameter = new JSONObject();
        final TextView textView1 = (TextView) findViewById(R.id.txt1);

        try {


            httppost.setEntity(new StringEntity(jsonparameter.toString(),
                    "UTF-8"));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            String responseString = EntityUtils.toString(entity);

            Log.i("@akis_responseString", "" + responseString);



            try {
                returndata = new JSONObject(responseString);
                JSONArray jsonMainNode = returndata.optJSONArray("d");
                int lengthJsonArr = jsonMainNode.length();
                akis_soru_sorusayisi = lengthJsonArr;
                Log.i("Log_jsonlength", "" + akis_soru_sorusayisi);

                for (; bas_i < akis_soru_sorusayisi; bas_i++) {


                    JSONObject jsonChildNode = jsonMainNode
                            .getJSONObject(bas_i);

                    try {

                        Type = jsonChildNode.optString("Type").toString();
                        Log.i("@Log_Type", "" + Type);

                        if (Type.equals("Soru")) {



                            id = jsonChildNode.optInt("ID");
                            Log.i("@Log_id", "" + id);

                            GrpID = jsonChildNode.optInt("GrpID");
                            Log.i("@Log_GrpID", "" + GrpID);

                            TypeID = jsonChildNode.optInt("TypeID");
                            Log.i("@Log_TypeID", "" + TypeID);

                            break;

                        }





                    } catch (Exception e) {



                        Log.i("ErrorMessage", "" + e.getMessage());

                    }
                }

            } catch (JSONException e) {

            }

        } catch (Exception e) {

        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return TypeID;

}

private void Cevapla(int i, int question_id) {
    // TODO Auto-generated method stub

    try {

        Thread.sleep(1500);

        Oyla(i, question_id);

        // SonrakiSoruKontrol();

        getType();

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }

}



private void getType() {
    // TODO Auto-generated method stub

    try {
        new Thread(new Runnable() {
            @Override
            public void run() {

                JSONObject returndata = null;
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(
                        "http://78.186.62.169:8210/AnketServis.asmx/Akis");
                httppost.setHeader("Content-type", "application/json");
                JSONObject jsonparameter = new JSONObject();

                try {

                    httppost.setEntity(new StringEntity(jsonparameter
                            .toString(), "UTF-8"));
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
                    String responseString = EntityUtils.toString(entity);

                    Log.i("@akis_responseString_Soru_Akiss", ""
                            + responseString);



                    try {

                        int inc_bas_i = bas_i + 1;
                        Log.i("inc_sonraki_soru_id", "" + inc_bas_i);

                        returndata = new JSONObject(responseString);
                        JSONArray jsonMainNode = returndata
                                .optJSONArray("d");
                        int lengthJsonArr = jsonMainNode.length();
                        int sorusayisi = lengthJsonArr;
                        Log.i("Log_jsonlength_Soru_Akis", "" + sorusayisi);

                        for (; inc_bas_i < sorusayisi; inc_bas_i++) {


                            JSONObject jsonChildNode = jsonMainNode
                                    .getJSONObject(inc_bas_i);

                            try {

                                last_Type_inmethod = jsonChildNode
                                        .optString("Type").toString();

                                Log.i("@Log_Type_Soru_Akis", "" + Type);

                                if (last_Type_inmethod.equals("Soru")) {

                                    Intent pass_other_activty = new Intent(
                                            getApplicationContext(),
                                            SonrakiActivity.class);
                                    data_gonder.putInt(
                                            "data_sonraki_soru_id",
                                            inc_bas_i);
                                    pass_other_activty
                                            .putExtras(data_gonder);

                                    startActivity(pass_other_activty);

                                    break;
                                }

                                if (last_Type_inmethod.equals("Bitis")) {

                                    Intent pass_other_activty = new Intent(
                                            getApplicationContext(),
                                            BitisMesage.class);


                                    startActivity(pass_other_activty);

                                    break;
                                }

                                if (last_Type_inmethod
                                        .equals("Kullanıcı  Girisi")) {

                                    Intent pass_other_activty = new Intent(
                                            getApplicationContext(),
                                            KullaniciGirisi1.class);
                                    data_gonder.putInt(
                                            "data_sonraki_soru_id",
                                            inc_bas_i);
                                    pass_other_activty
                                            .putExtras(data_gonder);

                                    startActivity(pass_other_activty);
                                    //

                                    break;
                                }




                            } catch (Exception e) {

                                Log.i("ErrorMessage", "" + e.getMessage());

                            }
                        }

                    } catch (JSONException e) {

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(
                                        getApplicationContext(),
                                        "İnternet ayarlarınızı kontrol ediniz",
                                        Toast.LENGTH_SHORT).show();
                            }
                        });

                    }

                } catch (Exception e) {

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(),
                                    "İnternet ayarlarınızı kontrol ediniz",
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                }

            }
        }).start();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

private void Oyla(final int cevabim_id, final int questionn_id) {

    // TODO Auto-generated method stub

    try {
        new Thread(new Runnable() {
            @Override
            public void run() {

                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(
                        "http://78.186.62.169:8210/AnketServis.asmx/Oyla");

                httppost.setHeader("Content-type", "application/json");
                httppost.setHeader("Accept", "application/json");

                JSONObject jsonparameter = new JSONObject();

                try {

                    Log.i("question_iddd", "" + questionn_id);
                    Log.i("question_iddd", "" + cevabim_id);

                    jsonparameter.put("ID", questionn_id);
                    jsonparameter.put("CevapID", cevabim_id);

                    try {
                        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
                        String deviceID = telephonyManager.getDeviceId();
                        jsonparameter.put("IMEI", deviceID);
                    } catch (Exception e) {
                        jsonparameter.put("IMEI", "IMEI Yok");
                    }
                    httppost.setEntity(new StringEntity(jsonparameter
                            .toString(), "UTF-8"));

                    httpclient.execute(httppost);



                } catch (Exception e) {

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(),
                                    "İnternet Ayarlarınızı Kontrol Ediniz",
                                    Toast.LENGTH_SHORT).show();
                        }
                    });

                    e.printStackTrace();
                }
            }
        }).start();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

private int Akis_GrpID() {
    try {

        JSONObject returndata = null;
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "http://78.186.62.169:8210/AnketServis.asmx/Akis");
        httppost.setHeader("Content-type", "application/json");
        JSONObject jsonparameter = new JSONObject();
        final TextView textView1 = (TextView) findViewById(R.id.txt1);

        try {

            // jsonparameter.put("AnketID", "3");

            httppost.setEntity(new StringEntity(jsonparameter.toString(),
                    "UTF-8"));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            String responseString = EntityUtils.toString(entity);

            Log.i("@akis_responseString", "" + responseString);



            try {
                returndata = new JSONObject(responseString);
                JSONArray jsonMainNode = returndata.optJSONArray("d");
                int lengthJsonArr = jsonMainNode.length();
                sorusayisi = lengthJsonArr;
                Log.i("Log_jsonlength", "" + sorusayisi);

                for (; bas_i < sorusayisi; bas_i++) {

                    // if (i == sorusayisi)
                    // break;
                    JSONObject jsonChildNode = jsonMainNode
                            .getJSONObject(bas_i);

                    try {
                        Type = jsonChildNode.optString("Type").toString();

                        Log.i("@Log_Type", "" + Type);
                        if (Type.equals("Soru")) {

                            id = jsonChildNode.optInt("ID");
                            Log.i("@Log_id", "" + id);

                            GrpID = jsonChildNode.optInt("GrpID");
                            Log.i("@Log_GrpID", "" + GrpID);

                            TypeID = jsonChildNode.optInt("TypeID");
                            Log.i("@Log_TypeID", "" + TypeID);

                            break;
                        }





                    } catch (Exception e) {



                        Log.i("ErrorMessage", "" + e.getMessage());

                    }
                }

            } catch (JSONException e) {

            }

        } catch (Exception e) {

        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return GrpID;

}

public void Onceki_soru() {
    try {
        final GlobalClass globalVariable = (GlobalClass) getApplicationContext();
        final TextView txt_soru = (TextView) findViewById(R.id.textView1);
        // final TextView textViewhdn1 = (TextView)
        // findViewById(R.id.txthdn1);
        txt_soru.post(new Runnable() {
            @Override
            public void run() {
                try {

                    txt_soru.setText(globalVariable.getSorumuz());

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


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

}

0 个答案:

没有答案