I have an item
in 3 items, but when I click on it, the entire line is selected. I need each item item
clicked separately.
Tell setOnClickListener
how to setOnClickListener
to the adapter correctly?
public class MountainFragment extends ListFragment { public final static String TAG = MyTag.TAG_MOUNTAIN; private MountainShop mountainShop = new MountainShop(); @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); List<HashMap<String, String>> listMountainShop = new ArrayList<>(); ((MainActivity) getActivity()).setLastFragmentTag(this.getClass().toString()); for (int i = 0; i < mountainShop.getListShops().size(); i++) { HashMap<String, String> hm = new HashMap<>(); hm.put("img", Integer.toString(mountainShop.getIconShops().get(i))); hm.put("txt", mountainShop.getListShops().get(i)); hm.put("imgMy", Integer.toString(R.drawable.ic_control_point_black_24dp)); listMountainShop.add(hm); } String[] from = {"img", "txt", "imgMy"}; int[] to = {R.id.imgForList, R.id.textForList, R.id.imgForMyList}; SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), listMountainShop, R.layout.list_single, from, to); setListAdapter(adapter); view.setBackgroundResource(R.drawable.background_mountain); } @Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mountainShop.getLinkShop(position))); startActivity(intent); } }