我有一个带有 getView 的类,它处理 onclick 侦听器,该侦听器将删除 Arraylist 中的数据,该数据位于另一个在活动中扩展的类中,问题是它返回一个空指针。
这是我处理 Arraylist 的活动
public ArrayList<String> imagesFileName = new ArrayList<String>();
public ArrayList<HashMap<String, String>> mylist;
//method for deleting data in array list and will going to use in another class
public void deleteFile(int i){
imagesFileName.remove(i);
mylist.remove(i);
adapter.notifyDataSetInvalidated();
}
这是我的类,它包含一个 getView() 并将使用我在活动中声明的方法
Activity activity = new Activity();
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View rowView = null;
try{
rowView = inflater.inflate(resource, null, true);
TextView textViewTitle = (TextView) rowView.findViewById(to[0]);
EditText textViewSubtitle = (EditText) rowView.findViewById(to[1]);
TextView textViewSubtitle1 = (TextView) rowView.findViewById(to[2]);
TextView textViewSubtitle2 = (TextView) rowView.findViewById(to[3]);
final TextView textViewSubtitle3 = (TextView) rowView.findViewById(to[4]);
TextView textViewId = (TextView) rowView.findViewById(to[5]);
final String id = textViewId.getText().toString();
textViewSubtitle3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
activity.deleteFile(id);//here is my method in my Activiy
}
});
当我在同一活动中使用该方法时,它可以工作。但是当我将它用于另一个类时,它会返回一个 indexoutofbounds。