A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© a6566983 初级黑马   /  2014-10-26 09:31  /  855 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. public class MySimpleAdapter extends SimpleAdapter {
  2.         public MySimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {       
  3.                 super(context, data, resource, from, to);
  4.         }

  5.         @Override
  6.         public View getView(int position,View convertView, ViewGroup parent) {
  7.                 convertView = super.getView(position, convertView, parent);
  8.                 Button buttonAdd = (Button) convertView.findViewById(R.id.btnOrder);
  9.                 TextView tv1 = (TextView) convertView.findViewById(R.id.lblRoomType);
  10.                 final String roomType = tv1.getText().toString();
  11.                 buttonAdd.setOnClickListener(new View.OnClickListener() {
  12.                         public void onClick(View v) {
  13.                                 //请问此处跳转下个页面该怎么写
  14.                         }
  15.                 });
  16.                 return convertView;
  17.         }
  18. }
复制代码
用这个是不行的,继承的SimpleAdapter里面都没startActivity
Intent intent = new Intent(Context packageContext, Class<?> cls);
startActivity(intent);

请指点~

1 个回复

倒序浏览
学习不能学这么死板。。
你为什么不能用startActivity?是因为你没有继承activity类。但是你已经继承了其他的类,那么你可以用构造方法,把activity或者context传过来。下面代码,你看一下
  1. public class MySimpleAdapter extends SimpleAdapter {
  2.                   private Context con;
  3.         public MySimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
  4.                                   con = context;       
  5.                 super(context, data, resource, from, to);
  6.         }

  7.         @Override
  8.         public View getView(int position,View convertView, ViewGroup parent) {
  9.                 convertView = super.getView(position, convertView, parent);
  10.                 Button buttonAdd = (Button) convertView.findViewById(R.id.btnOrder);
  11.                 TextView tv1 = (TextView) convertView.findViewById(R.id.lblRoomType);
  12.                 final String roomType = tv1.getText().toString();
  13.                 buttonAdd.setOnClickListener(new View.OnClickListener() {
  14.                         public void onClick(View v) {
  15.                                 Intent intent = new Intent(Context packageContext, Class<?> cls);
  16.                                                              con.startActivity(intent);

  17.                             }
  18.                 });
  19.                 return convertView;
  20.         }
  21. }
复制代码
回复 使用道具 举报 1 0
您需要登录后才可以回帖 登录 | 加入黑马