大家好,我有以下代码从服务器上撤回一些数据,当我点击任何项目时,它会显示从服务器检索的ID。而不是在吐司中显示我想传递给另一个活动。这是原始代码
public class Test extends ListActivity {
Prefs myprefs = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listplaceholder);
this.myprefs = new Prefs(getApplicationContext());
// install handler for processing gui update messages
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
JSONObject json = JSONfunctions.getJSONfromURL("http://midsweden.gofreeserve.com/proj/androidjson.php?identifier=" +
Test.this.myprefs.getPersonalno());
try{
JSONArray earthquakes = json.getJSONArray("services");
for(int i=0;i<earthquakes.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = earthquakes.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("pic", "Service name : " + e.getString("employeepic"));
map.put("serviceinfo", "" + e.getString("employeename")+ " : "+ e.getString("starttime")
+" To " + e.getString("endtime"));
mylist.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.test,
new String[] { "servicename", "serviceinfo" },
new int[] { R.id.item_title, R.id.item_subtitle });
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Toast.makeText(Test.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show();
}
});
}
我正在尝试调整此代码,但每次&#34;强制关闭&#34;
Intent intent = new Intent(Test.this, passing.class);
intent.putExtra("Employename", employeename);
startActivity(intent);
以下列方式完成id。但现在如何用hireename取代它
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Intent intent = new Intent(Test.this, passing.class);
intent.putExtra("id", id);
startActivity(intent);
}
});
}
答案 0 :(得分:2)
您好我向您提出了几个问题...您是否尝试在您拥有Toast声明的地方插入新的活动部分。如果是这样,插入后强制关闭对话框来了..请检查你是否有名称传递的类,并在清单中定义了一个活动...如果你仍然得到强制关闭anr只是发布你的logcat这将有所帮助我们来解决你的问题..