I have a class with a getView and it handle the the onclick listener that will delete data in Arraylist which is in another class that extends in activity the problem is it returns me a null pointer.
Here is my activity which handles the 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();
}
Here is my class that holds a getView() and will going to use the method I declared in the activity
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
}
});
When I use the method in the same activity it works. But when I'm using it to another class it return me an indexoutofbounds.
I finally figure it out all I need is to join my Activity and the Class in one page for be able a Class to access my array list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With