这是正在运行的代码,Android 已停止,但得到了正确的 json,列表视图可能有问题,我是否必须在某些地方使用 listview id.. 我的 listview id 是“list”..
*public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_jobs);
kywrd = getIntent().getExtras().getString("Keyword");
loc = getIntent().getExtras().getString("Location");
farea = getIntent().getExtras().getString("Funcarea");
exp = getIntent().getExtras().getString("Experience");
indus = getIntent().getExtras().getString("Industry");
jobList = new ArrayList<HashMap<String, String>>();
new postdetails().execute();
ListView lv = getListView();
// on seleting single product
// launching Edit Product Screen
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String pid = ((TextView) view.findViewById(R.id.txttitle)).getText()
.toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(),
ViewJob.class);
// sending pid to next activity
in.putExtra (TAG_JOBTITLE,pid);
// starting new activity and expecting some response back
startActivityForResult(in, 100);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted product
// reload this screen again
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
class postdetails extends AsyncTask<String,String,String>
{
String validUser = "false";
protected void OnPreExecute() {
super.onPreExecute();
pDialog=new ProgressDialog(SearchResult.this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
pDialog.setIndeterminate(false);
pDialog.show();
}
protected String doInBackground(String... args)
{
params.add(new BasicNameValuePair("Job_Keyword",kywrd));
params.add(new BasicNameValuePair("All_Location",loc));
params.add(new BasicNameValuePair("Job_Func_Area",farea));
params.add(new BasicNameValuePair("Job_Max_Exp",exp));
params.add(new BasicNameValuePair("Job_Industry","indus"));
JSONObject json = jParser.makeHttpRequest(url,"POST",params);
Log.d("user : ", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1)
{
user = json.getJSONArray(TAG_JOB);
validUser = "true";
// looping through All Products
for (int i = 0; i < user.length(); i++) {
JSONObject c = user.getJSONObject(i);
// Storing each json item in variable
String title = c.getString(TAG_JOBTITLE);
String loca = c.getString(TAG_JOBLOC);
HashMap<String, String> map = new HashMap<String, String>(); map.put(TAG_JOBTITLE,title);
map.put(TAG_JOBLOC,loca);
jobList.add(map);
}
}
else
validUser = "false";
} catch (JSONException e) {
e.printStackTrace();
}
return validUser;
}
protected void onPostExecute(String validUser) {
pDialog.dismiss();
if(validUser=="true")
{
ListAdapter adapter = new SimpleAdapter(
SearchResult.this,jobList,
R.layout.job_list, new String[] {TAG_JOBTITLE,
TAG_JOBTITLE},
new int[] { R.id.txttitle,R.id.txtloc});
setListAdapter(adapter);
}
params.clear();
}
}
}***