[english follows]
Hallo,
anbei die Lösung zu meinem Problem.
Ich habe schlicht den falschen Listener verwendet - View.OnLongClickListener statt AdapterView.OnItemLongClickListener.
-------
Hi,
please find attached the solution to my problem.
I simply used the wrong kind of Listener - View.OnLongClickListener instead of AdapterView.OnItemLongClickListener.
Code
package com.example.longclicktest;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemLongClickListener;
public class MyListFragment extends ListFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
String[] items = { "this", "is", "a", "really", "silly", "list" };
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1, items));
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ListView listView = getListView();
listView.setLongClickable(true);
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getActivity(), "Long press!", Toast.LENGTH_SHORT).show();
return true;
}
});
}
}
Alles anzeigen