Wenn ich auf die Schaltfläche klicken, wird keine Nachricht angezeigt, aber wenn ich auf das Listenansichtselement klicke und dann auf die Schaltfläche klickt, wird die Nachricht angezeigt.Schaltfläche von benutzerdefinierten ListView reagiert nicht
was ist wollen, ist meine Datenbank zu aktualisieren, indem Sie auf die Schaltfläche jeder listview Elemente klicken. Ich habe android:focusable="false" android:focusableInTouchMode="false"
in list_items.xml
Taste verwendet.
productListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Button saleBtn = (Button) view.findViewById(R.id.sale_btn);
if (saleBtn != null) {
saleBtn .setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "clicked",
Toast.LENGTH_SHORT).show();
}
});
}
}
});
Der Artikel Layout für list_items.xml
sich wie folgt:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="@+id/sale_btn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Sale"
android:textAppearance="?android:textAppearanceSmall"
android:textStyle="bold" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical">
<TextView
android:id="@+id/product_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif-medium"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="#2B3D4D"
android:textStyle="bold"
tools:text="Product" />
<TextView
android:id="@+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif-medium"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="#2B3D4D"
android:textStyle="bold"
tools:text="Quantity" />
<TextView
android:id="@+id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif-medium"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="#2B3D4D"
android:textStyle="bold"
tools:text="Price" />
</LinearLayout>
</LinearLayout>
Bitte geben Sie Ihre Artikel Layout. –
http://pastebin.com/i1emQfn8 Dies ist der Link für die list_item.xml – osh
Sieht gut aus, haben Sie versucht, diesen Code in einem Schritt debuggen? –