我有一个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 我刚刚发现,它不会跳过 new get_details().execute(); 而是在 new get_details().execute(); 之后停止 被执行..我该如何解决这个问题?