ListItem onClick issue
I have a listview and in each of listitems I am adding a checkbox, two textviews and imageview. What I want is to have a click action on listitem and a separate click action on imageview as well (which lies in the lis开发者_如何学编程titem).
I used the following code for itemclick event :lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
CustomizeDialog customizeDialog = new CustomizeDialog(desserts.this); // Used to show a dialog
customizeDialog.show();
// TODO Auto-generated method stub
}
});
Also on clicking item checkbox is checked. So, two things are happening (checkbox is checked and dialog appears), which is true according to functionality. I want that when user clicks the listitem checkbox is checked or unchecked and no dialog should appear, and when user click imageview on same listitem,only a dialog is shown above and no checkbox is checked or unchecked.
How can I achieve that? Please help.Stone
you need to use an Adapter and set your listeners for your checkbox and dialog in the getView() of this adapter.
see: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
Update textView from an item in a custom listView Android
set the listener into the getView()
like for example:-
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.list_layout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.image1 = (ImageView) view.findViewById(R.id.image1);
viewHolder.image1.setOnClickListener(new OnClickListener(){
@Override
public voic onClick(View v){
// do something here
}
});
viewHolder.text1 = (TextView) view.findViewById(R.id.text1);
viewHolder.checkBox = (CheckBox) view.findViewById(R.id.checkbox);
viewHolder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// do something
}
});
view.setTag(viewHolder);
精彩评论