I bet you get confused why the ListView object does not capture click events at times. Ever thought that maybe the components within each ListView entry contain components that accept input events?

Take for example EditText or a Spinner? If this was a regular TextView, then there will definitely be no problem when it comes to capturing click events in the OnItemClickListener or OnItemLongClickListener().

What you can do to fix this is to set your EditText component to disable events so these such events will be relegated to the ListView.

You can do this by setting android:focusable=”false” and android:focusableInTouchMode=”false” in the XML layout file. Try it and check it out.

You will see that by setting these attributes to false in your EditText, your ListView object can then capture click events.

Most likely you encountered this exception

ClassCastException: LinearLayout$LayoutParams Cannot Be Cast to AbsListView$LayoutParams

because you either added a header and/or footer in the ListView component and when you removed them, you found out there was no error generated.

Explanations aside, to fix this problem just set the LayoutParams of your header or footer like this:

That should solve it.

Adding a Button node inside a ListView in Java FX 2 is pretty easy. Create a custom class that extends ListCell and integrate your object within it. See my sample class code.

Then use the class in the ListView object by doing it like this:

That’s it! Easy, right?

Related Posts Plugin for WordPress, Blogger...