I have a custom list view,List view item has a button, I can't click on the list item itself, the only thing is clickable is the button.
I want to be able to click the list item and the button separately.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
itemView = (itemView == null) ? inflater.inflate(R.layout.listview_layout, null) : itemView;
TextView textViewName = itemView.findViewById(R.id.headtext);
TextView textViewDescription = itemView.findViewById(R.id.disctext);
ImageView stationImage = itemView.findViewById(R.id.image);
//ImageButton favButton = itemView.findViewById(R.id.favbutton);
FloatingActionButton favButton = itemView.findViewById(R.id.favbutton);
Station selectedStation = stations.get(position);
textViewName.setText(selectedStation.getStationName());
textViewDescription.setText(selectedStation.getDescription());
stationImage.setImageResource(selectedStation.getStationImg());
checkFavForBtn(favButton, selectedStation);
favButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
LibraryUtil.setFavoritesLibrary(selectedStation, context);
System.out.println("Saving");
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
checkFavForBtn(favButton, selectedStation);
//notifyDataSetChanged();
}
});
return itemView;
}
click listener for the listview -
lst.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//my code
}
});
What should I do? Thank you in advance!
Found the solution
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent serviceIntent = new Intent(finalItemView.getContext(), BackgroundSoundService.class);
serviceIntent.putExtra("position", position);
serviceIntent.putExtra("whatlibrary", 1);
finalItemView.getContext().startService(serviceIntent);
}
});
favButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
LibraryUtil.setFavoritesLibrary(selectedStation, context);
System.out.println("Saving");
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
checkFavForBtn(favButton, selectedStation);
//notifyDataSetChanged();
}
});