当前位置: 代码迷 >> Java相关 >> android ListView 中的onItemClick Intent 没法跳转
  详细解决方案

android ListView 中的onItemClick Intent 没法跳转

热度:1769   发布时间:2013-02-25 21:52:15.0
android ListView 中的onItemClick Intent 无法跳转
android ListView 中的onItemClick Intent 无法跳转

Java code
protected void onCreate(Bundle savedInstanceState) {    // TODO Auto-generated method stub    super.onCreate(savedInstanceState);    setContentView(R.layout.source_list);    ListView lv = (ListView) this.findViewById(R.id.listView);    // 生成动态数组,加入数据    ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();    for (int i = 0; i < 10; i++) {        HashMap<String, Object> map = new HashMap<String, Object>();        map.put("ItemImage", R.drawable.bt);// 图像资源的ID        map.put("ItemTitle", "Level " + i);        map.put("ItemText", "Finished in 1 Min 54 Secs, 70 Moves! ");        listItem.add(map);    }    // 生成适配器的Item和动态数组对应的元素    SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem,// 数据源        R.layout.context,// ListItem的XML实现        // 动态数组与ImageItem对应的子项        new String[] { "ItemImage", "ItemTitle", "ItemText" },        // ImageItem的XML文件里面的一个ImageView,两个TextView ID        new int[] { R.id.ItemImage, R.id.ItemTitle, R.id.ItemText });    // 添加并且显示    lv.setAdapter(listItemAdapter);    // 添加点击    lv.setOnItemClickListener(new OnItemClickListener() {        @Override        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,            long arg3) {        // Toast.makeText(SourceList.this, "点击第"+arg2+"个项目", 1).show();        Intent intent = new Intent(SourceList.this, ViewDetail.class);        startActivity(intent);                //这里无法跳转        }    });    }


ViewDetail.class
应该不关这个的事
Java code
protected void onCreate(Bundle savedInstanceState) {        // TODO Auto-generated method stub        super.onCreate(savedInstanceState);        this.setContentView(R.layout.view_detail);    }


------解决方案--------------------------------------------------------
应该是new intent.setclass(SourceList.this, ViewDetail.class)
------解决方案--------------------------------------------------------
你在AndroidManifest.xml定义ViewDetail这个activity没?
  相关解决方案