3

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.

3 Answers 3

3

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.

0

Argument type of deleteFile() is integer, but you called it by passing string in getView() function. You may check this problem first.

0
0

Personally, I would put the array in shared preferences. This means you would be accessing the data in a standard and well-understood way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.