I want to create a listview that is similar in functionality to the Gmail android app. By that I mean that you can select rows by clicking an image on the left or view an email by clicking anywhere else on the row. I can come close, but it's not quite there.
My custom row consists of an ImageView on the left and some TextViews on the right. Here's the gist of the getView on my Adapter.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getListView().setItemChecked(position, !getListView().isItemChecked(position));
}
});
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), "" + position, Toast.LENGTH_SHORT).show();
}
});
}
This comes very close! What's missing is the highlighting of the row on the row click listener.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…