我有一個getView類,它處理的onclick監聽器將刪除Arraylist中的數據,該數據位於另一個在活動中擴展的類中,問題是它返回一個null指針。如何從另一個活動刪除數組列表中的數據
這裏是我的活動它處理的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。
我已經解析到int但不起作用。 – NewDroidDev