谁能帮我..??我的问题是,在从 json [它来自 web 服务,因为有选择查询来获取记录] 的响应后,而不是显示在列表视图中,它返回到上一个屏幕这是我的示例代码..
public class MainActivity5 extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_list_view);
Intent i = getIntent();
phNumber = i.getStringExtra("phn_no");
new SearchCustomer().execute();
ListAdapter adapter = new SimpleAdapter(this, customerList, R.layout.activity_main5, new String[] { TAG_F_NAME, TAG_C_PHONE }, new int[] { R.id.TextViewName, R.id.TextViewPhone });
setListAdapter(adapter);
}
class SearchCustomer extends AsyncTask<String, String, String> {
private boolean successFlag;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity5.this);
pDialog.setMessage("Searching Customer..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
String inputPhnNoText = phNumber;
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("phno", inputPhnNoText));
JSONObject json = jsonParser.makeHttpRequest(url_search_customer, "POST", params);
Log.d("Search Response", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
successFlag = true;
result = json.getJSONArray(TAG_RESULT);
for (int i = 0; i < result.length(); i++) {
JSONObject c = result.getJSONObject(i);
String id = c.getString(TAG_ID);
String fname = c.getString(TAG_F_NAME);
String phoneNumber = c.getString(TAG_C_PHONE);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_ID, id);
map.put(TAG_F_NAME, fname);
map.put(TAG_C_PHONE, phoneNumber);
// adding HashList to ArrayList
customerList.add(map);
}
}
else {
successFlag = false;
}
}
catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
finish();
}
}
}
这是我的活动文件代码..在doinbackground customerList中我得到了我想要的确切数据,但问题是它没有留在custom_list_view屏幕中,它返回到有文本框和搜索按钮的上一个屏幕..所以不能显示记录...
请问大家,有没有人可以解决这个愚蠢的事情?