Skip to content

Instantly share code, notes, and snippets.

@muayyad-alsadi
Created December 26, 2013 13:50
Show Gist options
  • Save muayyad-alsadi/8134064 to your computer and use it in GitHub Desktop.
Save muayyad-alsadi/8134064 to your computer and use it in GitHub Desktop.
listView with onclick
static class MyViewHolder { ImageView logo; TextView name, foo, bar;}
public View getView (int position, View v, ViewGroup parent) {
MyType item=getItem(position);
MyViewHolder holder;
if (v==null) {
v = adapter.inflater.inflate(R.layout.my_row, null, false);
holder = new MyViewHolder();
holder.logo=(ImageView) v.findViewById(R.id.logo);
holder.name=(TextView) v.findViewById(R.id.name);
v.setTag(holder);
} else {
holder = (MyViewHolder) v.getTag();
}
holder.name.setText(item.name);
}
// ----------
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view,
int pos, long id) {
MyType item=adapter.getItem(pos);
MyActivity.onItemClicked(pos, item);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment