I have a listView inside a Fragment and from each item I open a different activity, but after I put an OnItemLongClickListener to open an AlertDialog when each item is pressed the OnListItemClick has "stopped" working. As a Custom Array Adapter I have a RelativeLayout with 16dp padding, and the OnListItemClick only works by clicking outside the Relative Layout
This is XML with custom items
<RelativeLayout
android:id="@+id/text_container"
android:layout_width="match_parent"
android:layout_height="200dp"
android:longClickable="true"
android:clickable="true"
android:background="@color/lista_background"
android:orientation="horizontal">
<TextView
android:id="@+id/txt_item_list"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:fontFamily="cursive"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="43sp"
android:textStyle="bold"
tools:text="@string/txt_lista" />
<ImageView
android:id="@+id/image_list"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_alignParentRight="true"
android:layout_marginRight="40dp"
android:layout_marginTop="20dp"/>
</RelativeLayout>
This part with the OnItemClickListener and the OnItemLongClickListener
View rootView = inflater.inflate(R.layout.my_list, container, false);
ArrayList<Itens> itens = new ArrayList<Itens>();
itens.add(new Itens("Primeira", R.drawable.img));
itens.add(new Itens("Segunda", R.drawable.img));
itens.add(new Itens("Terceira", R.drawable.img));
MyAdapter adapter = new MyAdapter(getActivity(), itens, R.color.lista_background);
ListView listView = (ListView) rootView.findViewById(R.id.list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id){
if(position == 0) {
Intent intent = new Intent(getActivity(), PrimeiraActivity.class);
startActivity(intent);
}
if(position == 1) {
Intent intent = new Intent(getActivity(), SegundaActivity.class);
startActivity(intent);
}
if(position == 2) {
Intent intent = new Intent(getActivity(), TerceiraActivity.class);
startActivity(intent);
}
}
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
if(position == 0) {
PrimeiroDialogFragment dialogFragment = new PrimeiroDialogFragment();
dialogFragment.show(getChildFragmentManager(), "sobre");
}
if(position == 1) {
SegundoDialogFragment dialogFragment = new SegundoDialogFragment();
dialogFragment.show(getChildFragmentManager(), "sobre");
}
if(position == 2) {
TerceiroDialogFragment dialogFragment = new TerceiroDialogFragment();
dialogFragment.show(getChildFragmentManager(), "sobre");
}
return true;
}
});
return rootView;