I am using the droidQuery library to add some gesture detection to my app. I was having trouble adding the SwipeInterceptorView in my xml file (see original question here, so I define it inside my onCreate method and give it the same parameters. Then I add it to my layout using layout.addView(swipeInterceptorView). I attempted to add it to my XML layout file, but I got an error.
Is defining the SwipeInterceptorView programatically good practice, or should I add it to my XML file? If I should, how can I fix this XML file? :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/table"
android:orientation="vertical" >
<self.philbrown.SwipeInterceptorView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_view"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</self.philbrown.SwipeInterceptorView>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
When I use this layout, I get the Runtime error java.lang.ClassNotFoundException.
Also, i know how to add the onClickListener to an ImageView, but could anyone tell me how I should add the listener to a TextView also?
Thanks for any help!
It is best practice to define the
ViewinXML, since this provides a reusable file (so you can using it elsewhere in your app, or again in another app).That said, it is not bad practice to instantiate it programmatically - it just reduces the reusability factor.
I am currently unsure as to why this is not working. I will be looking into it in more detail ASAP. In the mean time, one sure thing would be to download the entire project, import it into your workspace, and add it as a library project, rather than a jar.
You can add the click listener exactly the same way:
If you want to make full use of the
droidQuerylibrary, you can optionally use one of these methods instead:click
on
one (only handles click once)
bind