1

リスナーに問題があり、ArrayAdapter を使用してリストを作成し、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>

そして、画像のリスナー。しかし、アイテムをクリックするとイベントが呼び出され、画像をクリックしないと同じ..

私のアダプタークラス:

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;

} 

そして、私には別の問題があります。おそらく同じ理由で発生したのでしょう。画像をクリックしても画像のフォーカスがありませんが、次のような問題があります。

<?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>

あなたの答えを前もってありがとう、そして私の悪い英語でごめんなさい:)

4

1 に答える 1