私は持っていgridview
ます。そのグリッドの項目をクリックすると、 という名前のクラスが呼び出されget_details
ます。私の問題は、グリッドからアイテムを最初にクリックするとスキップnew get_details().execute();
することですが、次のクリック後にはすでに機能しています..助けてください..
これが私のコードです
gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
final globalVars globalVars = (globalVars) getApplicationContext();
String sel_id = ca_list.get(arg2).stud_id;
globalVars.setClickedGrid(sel_id);
Log.i("SELECT", sel_id);
new get_details().execute();
String p_id = globalVars.getPopupID().toString();
String p_name = globalVars.getPopupName().toString();
String p_absent = globalVars.getPopupAbsent().toString();
String p_late = globalVars.getPopupLate().toString();
Log.i("SHOW CALL" , p_name);
int y = arg1.getTop();
int x = arg1.getLeft();
showPopup(ViewAttendanceSP.this, x, y, p_id, p_name, p_absent, p_late);
}
});
get_details クラス
private class get_details extends AsyncTask<String, Integer, String>
{
@Override
protected String doInBackground(String... arg0)
{
InputStream is = null;
String result = "";
String bidSt = dispid.getText().toString();
globalVars globalVars = (globalVars)getApplicationContext();
String idSt = globalVars.getClickedGrid().toString();
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.59.1/sp/viewsumsp.php");
List<NameValuePair> parameter = new ArrayList<NameValuePair>();
parameter.add(new BasicNameValuePair("student_id", idSt));
parameter.add(new BasicNameValuePair("beadle_id", bidSt));
httppost.setEntity(new UrlEncodedFormEntity(parameter));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e)
{
Log.e("log_tag", "Error in http connection " + e.toString());
}
try
{
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e)
{
Log.e("log_tag", "Error converting result " + e.toString());
}
return result;
}
@Override
protected void onPostExecute(String result)
{
super.onPostExecute(result);
ArrayList<HashMap<String, String>> to_take = new ArrayList<HashMap<String, String>>();
try
{
JSONObject jArray = new JSONObject(result);
JSONArray stud_info = jArray.getJSONArray("stud_info");
ca_list1 = new ArrayList<ViewAttendanceSummaryObject>();
for (int i = 0; i < stud_info.length(); i++)
{
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = stud_info.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("stud_id", e.getString("student_id"));
map.put("f_name", e.getString("first_name"));
map.put("l_name", e.getString("last_name"));
map.put("absence", e.getString("absence"));
map.put("lateness", e.getString("lateness"));
to_take.add(map);
Log.i("INNER" , e.getString("first_name"));
final globalVars globalVars = (globalVars) getApplicationContext();
String id = e.getString("student_id");
String name = e.getString("last_name") + ", " + e.getString("first_name");
String abs = e.getString("absence");
String lat = e.getString("lateness");
globalVars.setPopupID(id);
globalVars.setPopupName(name);
globalVars.setPopupAbsent(abs);
globalVars.setPopupLate(lat);
ca_list1.add(new ViewAttendanceSummaryObject(e.getString("student_id"), e.getString("first_name"), e.getString("last_name"), e.getString("absence"), e.getString("lateness")));
}
} catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
ps 新しい get_details().execute(); をスキップしないことがわかりました。むしろ、 new get_details().execute(); の後に停止します。実行されます..これを修正するにはどうすればよいですか?