I have got a problem with my Listener, i create a list with an ArrayAdapter and i set a text and an image for every item with WML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/item_macro"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/delete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:contentDescription="@string/button_delete"
android:src="@drawable/button_delete" />
</RelativeLayout>
And a listener for the images. But the event is calling when i click on the item, same when i click not on the image..
My adapter class:
public class ListEditable extends ArrayAdapter<Integer> implements OnClickListener, OnLongClickListener {
private final int rowResourceId;
public ListEditable(Context context, int resource, ArrayList<Integer> macros) {
super(context, resource, macros);
this.rowResourceId = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = (View) inflater.inflate(rowResourceId, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.item_macro);
ImageView imageView = (ImageView) rowView.findViewById(R.id.delete);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("toast");
}
});
textView.setText(this.getItem(position));
return rowView;
}
And i have an other problem, maybe it came for the same reason, i haven't the image focus when i click on my image, however i have:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/button_delete_focus" android:state_pressed="true"/>
<item android:drawable="@drawable/button_delete_focus" android:state_focused="true"/>
<item android:drawable="@drawable/button_delete"/>
</selector>
Thanks in advance for your answers, and sorry for my bad english :)