任何人都可以幫助我.. ??我的問題是,從json [它來自webservice,因爲有select select查詢記錄]得到響應後,而不是顯示在列表視圖它回到前一屏幕這裏是我的示例代碼..Android:從數據庫得到迴應後,回到前一屏幕
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屏幕中,它返回到上一個屏幕,其中有一個文本框和搜索按鈕。所以不能顯示記錄...
大家請,能有人給這個愚蠢的東西解決嗎?
喜奇拉格和CapDroid .. 感謝的是,通知我..它沒有回到先前的屏幕ATLEAST ..但問題仍然存在的數據在此屏幕顯示..並在logcat中我找到了這樣的響應:: {「result」:[{「customer_lname」:「last name」,「customer_fname」:「first name」,「customer_id」:「1」,「customer_phone」:「1111100000」}] 「成功」:1} 屏幕是空白..所以你可以幫助更多.. ?? –
檢查我的更新回答 –
非常感謝你兄弟..它的解決... :) –