这是我正在运行的代码,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();
}
}
}***
答案 0 :(得分:0)
确保您在listview中将您的ID设置为android:id="@android:id/list"
答案 1 :(得分:0)
尝试更改此
ListView lv = getListView();
到
ListView lv = (ListView)findViewById(android.R.id.list);
其中listview的id是“android:id / list”