0

I have class contains onListItemClick and onItemLongClick and the adapter class for list view. my problem is the onItemLongClick in never called how I can solve this?

public class FilePicker extends ListActivity implements AdapterView.OnItemLongClickListener {
...


@Override
protected void onListItemClick(ListView l, View v,int position, long id) {

    Toast.makeText(getApplicationContext(),"SHORT",Toast.LENGTH_LONG).show();


    super.onListItemClick(l, v, position, id);
}
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

Toast.makeText(getApplicationContext(),"LOOOONG",Toast.LENGTH_LONG).show();


    return true;
}
 private class FilePickerListAdapter extends ArrayAdapter<File> {

    private List<File> obj;


    public FilePickerListAdapter(Context context, List<File> objects) {

        super(context, R.layout.list_item_browse, android.R.id.text1, objects);
        obj = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View r = null;

        if(convertView == null) {

            LayoutInflater inflater = (LayoutInflater)
                    getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            r = inflater.inflate(R.layout.list_item_browse, parent, false);
        }
        else
            r = convertView;

        File object = obj.get(position);

        ImageView imageView = (ImageView)r.findViewById(R.id.file_picker_image);
        TextView textView = (TextView)r.findViewById(R.id.file_picker_text);
        textView.setSingleLine(true);
        textView.setText(object.getName());

        if(object.isFile())
            imageView.setImageResource(R.drawable.play);

        else
            imageView.setImageResource(R.drawable.folder);


        return r;
    }
}
}

I also tried android:longClickable="true" on RelativeLayout(list_item_browse) but it's not work.

KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
amir dt
  • 83
  • 2
  • 9

1 Answers1

0

You forgot to register click listener for the RelativeLayout.

Add yourRelativeLayout.setOnLongClickListener(this); inside getView after initializing the layout.

EDIT: if you want longclickListener for listview then register the listener with listview in you activity and implement the method in your activity

 yourListView.setOnItemLongClickListener(this);
Sharath kumar
  • 4,064
  • 1
  • 14
  • 20