The fact is that after some changes in the code (it will not be possible to roll back), the ListView is no longer clicked. Generally does not respond to click. I tried all sorts

listView.setClickable(true); listView.setItemsCanFocus(true); 

to no avail! I tried to create a new fragment with a new ListView and the same adapter. Again, click does not work. Maybe something is blocking clicks, tell me. 2 days I suffer ...

Here is a snippet where the ListView is defined:

 public class MainFragment extends Fragment { public static List<VacancyModel> vacancyModelList; SQLHelper sqlHelper; ArrayList<Integer> watchedVacanciesList; public static List<VacancyModel> safeVacancyModelList; int openedVacancyID; public static int page = 1; public static boolean fromSplash = true; ListView listView; MainVacancyAdapter adapter; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.main_layout, container, false); listView = (ListView) rootView.findViewById(R.id.lvMainFragment); listView.setClickable(true); listView.setItemsCanFocus(true); sqlHelper = new SQLHelper(getContext()); watchedVacanciesList = sqlHelper.haveWatchedVacancies(); if (fromSplash) { safeVacancyModelList = vacancyModelList; //Creating an adapter and setting it to the list adapter = new MainVacancyAdapter(getActivity().getApplicationContext(), R.layout.main_row_layout, vacancyModelList); } else { //Creating an adapter and setting it to the list adapter = new MainVacancyAdapter(getActivity().getApplicationContext(), R.layout.main_row_layout, safeVacancyModelList); } listView.setAdapter(adapter); listView.setOnItemClickListener(lvMainOnItemClickListener); return rootView; } public AdapterView.OnItemClickListener lvMainOnItemClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FragmentManager fm = getFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); MainBodyFragment fragment = new MainBodyFragment(); VacancyModel model; //getting data from operating memory and transmitting it through intent if (vacancyModelList != null) { model = vacancyModelList.get(position); openedVacancyID = vacancyModelList.get(position).getId(); } else { model = safeVacancyModelList.get(position); openedVacancyID = safeVacancyModelList.get(position).getId(); } sqlHelper.saveWatchedVacancy(openedVacancyID); Bundle bundle = new Bundle(); bundle.putSerializable(VacancyModel.class.getCanonicalName(), model); bundle.putInt(MainBodyFragment.MAIN_VACANCY_POSITION, position); fragment.setArguments(bundle); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace(R.id.fragment_switch, fragment); fragmentTransaction.commit(); } }; 

Adapter:

  public class MainVacancyAdapter extends ArrayAdapter { private List<VacancyModel> vacancyModelList; private List<Integer> favVacanciesIDList; private int resource; private LayoutInflater inflater; ArrayList<Boolean> isSelected; SQLHelper sqlHelper; ArrayList<Integer> watchedVacanciesList; public static int selectCount; public MainVacancyAdapter(Context context, int resource, List<VacancyModel> objects) { super(context, resource, objects); vacancyModelList = objects; this.resource = resource; sqlHelper = new SQLHelper(getContext()); favVacanciesIDList = sqlHelper.getFavVacanciesID(); watchedVacanciesList = sqlHelper.haveWatchedVacancies(); inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); } //Finding textViews and inserting data into them @Override public View getView(final int position, View convertView, final ViewGroup parent) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = inflater.inflate(resource, null); holder.tvProfession = (TextView) convertView.findViewById(R.id.tvProfession); holder.tvProfileName = (TextView) convertView.findViewById(R.id.tvProfileName); holder.tvSalary = (TextView) convertView.findViewById(R.id.tvSalary); holder.tvDate = (TextView) convertView.findViewById(R.id.tvPostCr); holder.cbxFav = (CheckBox) convertView.findViewById(R.id.cbxFav); holder.vacancyViewed = (LinearLayout) convertView.findViewById(R.id.viewedLayoutMain); holder.logo = (ImageView) convertView.findViewById(R.id.ivVacSource); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.tvProfession.setText(vacancyModelList.get(position).getProfession()); holder.tvProfileName.setText(vacancyModelList.get(position).getProfile()); holder.tvSalary.setText(vacancyModelList.get(position).getSalary()); holder.tvDate.setText(vacancyModelList.get(position).getDate()); try { //checking if there the same record exists in favourite table and tagging the star //checking if there is a vacancy that have been viewed for (int j = 0; j < watchedVacanciesList.size(); j++) { int recordID = vacancyModelList.get(position).getId(); int watchedRecordID = watchedVacanciesList.get(j); if (recordID == watchedRecordID) { holder.vacancyViewed.setVisibility(View.VISIBLE); } else { holder.vacancyViewed.setVisibility(View.GONE); } } } catch (NullPointerException e) { e.printStackTrace(); } //setting listener for changing the icon. Inserting determined rows in db and deleting it holder.cbxFav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // Here we get the position that we have set for the checkbox using setTag. int getPosition = Integer.parseInt(buttonView.getTag().toString()); int rowID = vacancyModelList.get(position).getId(); } }); return convertView; } static class ViewHolder { private TextView tvProfession; private TextView tvProfileName; private TextView tvSalary; private TextView tvDate; private CheckBox cbxFav; private LinearLayout vacancyViewed; private ImageView logo; } } 

main_layout.xml:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ListView android:id="@+id/lvMainFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="false" android:divider="@android:color/transparent" android:dividerHeight="5dp" android:listSelector="@color/transparent" android:padding="5dp"/> </LinearLayout> 

main_row.xml:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:background="@drawable/card_bg" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="horizontal" xmlns:android="http://schemas.android.com/apk/res/android"> <RelativeLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/relativeLayout2" android:layout_marginBottom="5dp"> <com.isakovch.Utils.Fonts.BoldFont android:ellipsize="end" android:id="@+id/tvProfession" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_centerVertical="true" android:layout_height="wrap_content" android:layout_width="match_parent" android:maxLines="1" android:text="Header" android:textColor="@color/colorPrimary" android:textSize="15dp" android:textStyle="bold" android:layout_toLeftOf="@+id/tvPostCr" android:layout_toStartOf="@+id/tvPostCr" android:layout_marginRight="10dp" android:layout_marginBottom="10dp" /> <com.isakovch.Utils.Fonts.LightFont android:id="@+id/tvPostCr" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="post created" android:textColor="#767676" android:textIsSelectable="false" android:textSize="11dp" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/relativeLayout2" android:id="@+id/relativeLayout3"> <ImageView android:id="@+id/imageView12" android:layout_height="30dp" android:layout_width="15dp" android:src="@drawable/ic_profile_name" /> <com.isakovch.Utils.Fonts.LightFont android:id="@+id/tvProfileName" android:layout_gravity="center" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Company" android:textColor="#767676" android:textSize="13dp" android:layout_centerVertical="true" android:layout_toRightOf="@+id/imageView12" android:layout_toEndOf="@+id/imageView12" android:layout_marginLeft="8dp" /> <ImageView android:id="@+id/ivVacSource" android:layout_height="35dp" android:layout_width="55dp" android:src="@drawable/ic_hh_kg" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="false" android:layout_alignParentStart="false" android:layout_below="@+id/relativeLayout3" android:id="@+id/relativeLayout"> <com.isakovch.Utils.Fonts.LightFont android:id="@+id/tvSalary" android:layout_gravity="center" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Salary" android:textColor="#767676" android:textSize="13dp" android:layout_centerVertical="true" android:layout_toRightOf="@+id/imageView10" android:layout_toEndOf="@+id/imageView10" android:layout_marginLeft="8dp" /> <CheckBox android:adjustViewBounds="true" android:checked="false" android:id="@+id/cbxFav" android:layout_height="40dp" android:layout_width="40dp" android:scaleType="fitCenter" android:layout_alignParentBottom="false" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:background="@drawable/custom_checkbox" android:button="@drawable/custom_checkbox_transparent" /> <ImageView android:contentDescription="@string/salary" android:id="@+id/imageView10" android:layout_height="30dp" android:layout_width="15dp" android:src="@drawable/ic_salary" android:layout_centerVertical="true" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/relativeLayout" android:layout_gravity="right" android:gravity="center_vertical" android:orientation="horizontal" android:id="@+id/viewedLayoutMain" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:visibility="gone"> <ImageView android:layout_width="15dp" android:layout_height="15dp" android:background="@drawable/ic_status_watched" /> <com.isakovch.aukg.Utils.Fonts.LightFont android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_margin="5dp" android:text="@string/status_watched" android:textColor="#767676" android:textSize="11dp" /> </LinearLayout> </RelativeLayout> 
  • show the layout of the adapter's items yet, there is a suspicion that the click intercepts holder.cbxFav.setOnCheckedChangeListener - s_klepcha
  • Updated ........ - DevOma
  • You were right. All comments with checkbox removed earned. But another question, how does he intercept? - DevOma
  • See how it is drawn in the layout - it is likely that it takes up all the space on top of the other views. - s_klepcha
  • Strange, but no, he is small. Commented back codes. And clicked on the checkbox it works, but the row is not clicked - DevOma

1 answer 1

An external click listener is conflating with everything clickable in the markup. The only solution is never to use external listeners and assign them only from inside the adapter, i.e. only in getView() method


And go to RecyclerView , which has no external listeners clicks and such a problem can not arise in principle.