0

我已将我在网上找到的自定义可扩展列表视图集成到我正在处理的项目中。我遇到的问题是从可扩展列表视图适配器中调用一个新活动。下面是适配器的部分代码。当 context.startActivity() 被调用时,我得到一个空异常错误。

关于如何调用新活动的任何想法

package com.example.apple;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;

@SuppressWarnings("unchecked")
public class NewAdapter extends BaseExpandableListAdapter {

 public ArrayList<String> groupItem, tempChild;
 public ArrayList<String> childDateTime;
 public ArrayList<Object> Childtem = new ArrayList<Object>();
 public LayoutInflater minflater;
 public Activity activity;
 private Context context;

 public NewAdapter(ArrayList<String> grList, ArrayList<Object> childItem, ArrayList<String> childDT) {
  groupItem = grList;
  this.Childtem = childItem;

  childDateTime = childDT;
 }

 public NewAdapter(Context context) {
     this.context = context;     
}

 public void setInflater(LayoutInflater mInflater, Activity act) {
  this.minflater = mInflater;
  activity = act;
 }

 @Override
 public Object getChild(int groupPosition, int childPosition) {
  return null;
 }

 @Override
 public long getChildId(int groupPosition, int childPosition) {
  return 0;
 }

 @Override
 public View getChildView(int groupPosition, final int childPosition,
   boolean isLastChild, View convertView, ViewGroup parent) {
  tempChild = (ArrayList<String>) Childtem.get(groupPosition);
  TextView text = null;
  if (convertView == null) {
   convertView = minflater.inflate(R.layout.activity_main_child, null);
  }
  text = (TextView) convertView.findViewById(R.id.textView1);
  text.setText(tempChild.get(childPosition));

  TextView dateTime = null;
  dateTime = (TextView) convertView.findViewById(R.id.textDateTime);
  dateTime.setText(childDateTime.get(groupPosition));

  convertView.setOnClickListener(new OnClickListener() {

@Override
   public void onClick(View v) {

       Intent intent= new Intent(context, ViewSomeStuff.class);

       context.startActivity(intent);
   }
  });
  return convertView;
 }
4

1 回答 1

2
public NewAdapter(Context context, ArrayList<String> grList, ArrayList<Object> childItem, ArrayList<String> childDT) {
  groupItem = grList;
  this.Childtem = childItem;

  childDateTime = childDT;
  this.context = context; 
 }
于 2013-05-25T23:19:48.630 回答