I'm having trouble adding an onClickListener to my custom list adapter, code below. OnListItemClick is applied as with a regular List View, but when any item is clicked, then "appears in LogCat excluding unregistered Listnr ....."
Any help would be greatly appreciated
MyListAdapter.java
import android.app.activity; Import android.content.Intent; Import android.view.LayoutInflater; Import android.view.View; Import android.view.View.OnClickListener; Import android.view.ViewGroup; Import android.widget.ArrayAdapter; Import android.widget.Button; Import android.widget.ImageButton; Import android.widget.ImageView; Import android.widget.TextView; Import android.widget.Toast; Public Class MyListAdapter ArrayAdapter Expanded & lt; String & gt; {Context of personal end activity; Private last string [] name; Static class viewer {public button button; Public image button image button; Public image button image button 2; } Public MyListAdapter (Activity Reference, String [] Name) {Super (Reference, R.Let.Custom_List_Stime, Name); This.context = context; This.names = names; } @ Override public view getView (integer position, seeviewview, ViewGroup parent) {see line view = convertview; If (line view == empty) {layout infletter inflater = context.getLayoutInflater (); Line view = inflater.inflate (R.layout.custom_list_item, tap); SeeHolderHolder = New Viewholder (); ViewHolder.button = (button) rowView.findViewById (R.id.txtTitle); ViewHolder.imageButton = (ImageButton) rowView.findViewById (R.id.moreInfo); ViewHolder.imageButton2 = (image button) rowView.findViewById (R.id.imgArrow); RowView.setTag (viewHolder); } Viewer holder = (seeholder) rowView.getTag (); String s = name [location]; Holder.button.setText (s); Holder.imageButton.setImageResource (R.drawable.more); Holder.imageButton2.setImageResource (R.drawable.arrow); Return line view; }} customer_list_item.xml
& lt ;? Xml version = "1.0" encoding = "utf-8" & gt; & Lt; LinearLayout xmlns: android = "Http://schemaskandroidkcom/apk/res/android" Android: Layout_width = "Fill_parent" Android: Layout_height = "Fill_parent" android: orientation = "horizontal" android: padding = "10 DP "& Gt; & Lt; Android: layout_highth = "fill_parent" android: layout_marginBottom = "5dp" Android: layout_marginRight = "15dp" Android: layout_marginTop = "5dp" Android: Background: ImageButton Android: id = "@ + id / moreinfo" Android: layout_width = "wrap_content" = "@ android: color / transparent" Android: contentDescription = "@ string / More_info" android: gravity = "Center_vertical" android: src = "@ drawable / more" / & gt; & Lt; Android: layout_marginBottom = "5dp" Android: layout_marginTop = "5dp" Android: layout_weight = "1" Android: Background: Android: layout_width = "fill_parent" android: layout_height = "fill_parent" Android: id = "@ + id / txtTitle" = "@ android: color / transparent" android: gravity = "Center_vertical" Android: textcolor = "# 000000" Android: textIsSelectable = "true" Android: textSize = "22sp" android: text-style = "bold" / & gt ; & Lt; Android: layout_marginBottom = "5dp" Android: layout_marginRight = "15dp" Android: layout_marginTop = "5dp" Android: background: ImageButton Android: id = "@ + id / imgArrow" Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" = "@ android: color / transparent" Android: contentDescription = "@ string / Select_trick" android: gravity = "Center_vertical" android: src = "@ drawable / arrow" / & gt; & Lt; / LinearLayout & gt;
arrow button, type the new class Clicker
applies the public class clicker View.OnClickListener {int position = 0; / * ------- Constructor to store the condition that the click event was triggered ---------- * / Public clicker {status = pos; // This will be the status of the selected items in the list. } Public Zero onClick (see v) {// your operation}} this Clicker call in getView method,
holder.imageButton2.setOnClickListener ( New clicker (status)); Use the same process for more info buttons
No comments:
Post a Comment