Question

I'm guessing this is just me doing something a bit dumb. I have a load of TextViews in my layout file which I'm using to create a number pad. They are 0-9 like this:

<TextView android:id="@+id/pad_number_7" android:text="@string/pad_number_text_7" style="@style/pad_button" />

The pad_button style includes:

<item name="android:clickable">true</item>

Then in my ControlExtension class' constructor I am calling a method called wireUpButtons() with code like this:

mLayout = parseLayout(((LayoutInflater)mContext.getSystemService("layout_inflater")).inflate(R.layout.pad_layout, null));
if (mLayout != null)
{
    Log.d("DK", "Adding event for button 7");
    ControlView controlview = mLayout.findViewById(R.id.pad_number_7);
    controlview.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(){
            Log.d("DK", "Button 7 clicked");
            sendResult("7");
        }
    });
}

And my onResume shows the layout:

@Override
public void onResume() {
    showLayout(R.layout.pad_layout, null);
}

But the log entry is never created and the call to sendResult doesn't happen. Does anyone know why my click events aren't firing? The call to wire up the event does happen, as the log first log entry is shown, and I've tried moving the call to wireUpButtons() to the onResume function (both before and after the showLayout call) with no change.

Was it helpful?

Solution

OK I realised I was missing the onObjectClick method to pass the click event up to the handler:

@Override
public void onObjectClick(final ControlObjectClickEvent event) {
    if (event.getLayoutReference() != -1) {
        mLayout.onClick(event.getLayoutReference());
    }
}

After adding this method it all works now

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top