Linkify Problem

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Linkify Problem

Postby D3viant » Thu Jun 03, 2010 8:50 pm

Has anyone been able to successfully implement Linkify for a ListView? If so could you provide me an example or point me in the right direction? Using Linkify on it throws a NullPointerException for some reason. I have also tried placing autoLink="all" in the XML but that throws a context error.

Any ideas?
D3viant
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue May 25, 2010 4:52 pm

Top

Re: Linkify Problem

Postby nicholas.hauschild » Fri Jun 04, 2010 1:12 am

Is the null pointer exception in your code, or in the android code? If it is in yours, I imagine it is something you need to fix...post a stack trace and a couple snippets of your code and we can see if we can help.

Good Luck!
-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Re: Linkify Problem

Postby D3viant » Mon Jun 07, 2010 4:59 pm

Sounds good, yeah I had forgotten to post the actual code. Here is what i'm looking at:

My listview:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.     <LinearLayout
  3.    android:id="@+id/widget54"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    xmlns:android="http://schemas.android.com/apk/res/android"
  7.    android:paddingBottom="20sp"  
  8.    android:background="#FFFFFF"
  9.    >
  10.            <ListView
  11.                 android:id="@id/android:list"
  12.                 android:layout_weight="1"
  13.                 android:drawSelectorOnTop="false"
  14.                 android:layout_width="fill_parent"
  15.                 android:layout_height="wrap_content"
  16.                 android:alwaysDrawnWithCache="true"
  17.                 android:cacheColorHint="@android:color/transparent"
  18.            >
  19.            </ListView>      
  20. </LinearLayout>
  21.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Here is the child view for the list.
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout
  3.         xmlns:android="http://schemas.android.com/apk/res/android"
  4.         android:orientation="vertical"
  5.         android:layout_width="fill_parent"
  6.         android:layout_height="fill_parent"
  7.         >
  8.                         <ImageView
  9.                                 android:id="@+id/photoAlbumImg"
  10.                                 android:layout_width="48px"
  11.                                 android:layout_height="48px"
  12.                                 android:padding="5px"
  13.                                 android:paddingRight="10px"
  14.                                 />
  15.  
  16.                         <TextView
  17.                                 android:id="@+id/rowText1"
  18.                                 android:layout_toRightOf="@id/photoAlbumImg"
  19.                                 android:layout_width="fill_parent"
  20.                                 android:layout_height="wrap_content"
  21.                                 android:textColor="#000000"
  22.                                 android:textSize="20sp"
  23.                                 android:paddingTop="10sp"
  24.                         />
  25.                         <TextView
  26.                         android:id="@+id/rowText2"
  27.                         android:layout_below="@id/rowText1"
  28.                 android:paddingLeft="50px"
  29.                         android:layout_width="fill_parent"
  30.             android:layout_height="wrap_content"               
  31.                         android:textColor="#000000"
  32.                         android:textSize="12sp"
  33.                         android:paddingBottom="10sp"
  34.                         android:autoLink="phone"
  35.                          />
  36. </RelativeLayout>
  37.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4



What i'm running into is that it links everything correctly. But when you actually click the phone number and it tries to fire the intent I get this:

06-07 16:00:16.491: ERROR/AndroidRuntime(183): Uncaught handler: thread main exiting due to uncaught exception
06-07 16:00:16.551: ERROR/AndroidRuntime(183): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.app.ApplicationContext.startActivity(ApplicationContext.java:550)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.content.ContextWrapper.startActivity(ContextWrapper.java:248)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.text.style.URLSpan.onClick(URLSpan.java:62)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:216)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.widget.TextView.onTouchEvent(TextView.java:6560)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.view.View.dispatchTouchEvent(View.java:3709)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.os.Looper.loop(Looper.java:123)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at android.app.ActivityThread.main(ActivityThread.java:4363)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at java.lang.reflect.Method.invokeNative(Native Method)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at java.lang.reflect.Method.invoke(Method.java:521)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-07 16:00:16.551: ERROR/AndroidRuntime(183): at dalvik.system.NativeStart.main(Native Method)



Any ideas? Thanks for taking a look!
D3viant
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue May 25, 2010 4:52 pm

Re: Linkify Problem

Postby D3viant » Mon Jun 07, 2010 10:24 pm

Nevermind I figured it out.


Turns out the answer to this is a lot simpler than I had originally thought. The problem was that when I was passing the context to my custom adapter I was passing the getApplicationContext() which is not the same as using the this identifier.

INCORRECT WAY:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Context mContext = getApplicationContext();
  2. CustomAdapter mAdapter = new CustomAdapter(
  3.                 mContext,
  4.                 itemList);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


CORRECT WAY:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. CustomAdapter mAdapter = new CustomAdapter(
  2.                 this,
  3.                 itemList);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
D3viant
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue May 25, 2010 4:52 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 17 guests