Use html hyperlinks to navigate

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

Use html hyperlinks to navigate

Postby Nibo » Fri Oct 15, 2010 4:23 pm

Hello
i try to use hyperlinks to navigate through html articles. The articles are stored in a sqlite database. Each Article contains hyperlinks with the respective ids to other articles.

Code: Select all

public class Entry extends Activity {

   /** Called when the activity is first created. */
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      
      // select the list layout
      setContentView(R.layout.entry);
      // get the extended data from the previous activity
      Bundle bundel = getIntent().getExtras();
      String content = bundel.getString("content");
      
      // generate displayable styled text
      CharSequence article = Html.fromHtml(content);
      TextView entryText = ((TextView) findViewById(R.id.Entry));
      entryText.setText(article);
      entryText.setLinksClickable(true);
      entryText.setMovementMethod(LinkMovementMethod.getInstance())      
   }
}

ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.View dat= *Article ID*} ...

I try to override some methods, use intent-filter, create listeners and test some tutorials...

I need somthing like an ActionListener on click with
Code: Select all
      // search the selected article and start the entry activity
      Intent intent = new Intent(Entry.this, Entry.class);
      intent.putExtra("content", getArticleByID(id));




Thankful for every advice. :roll:
Nibo
Freshman
Freshman
 
Posts: 2
Joined: Fri Oct 15, 2010 4:02 pm

Top

Re: Use html hyperlinks to navigate

Postby xantian15 » Sat Oct 16, 2010 9:56 am

I don't understand why you have "getIntent().getExtras();"
Intents are used to create new activitys. This is why it is complaining about no activity found.

Dave
xantian15
Freshman
Freshman
 
Posts: 5
Joined: Fri Oct 15, 2010 10:15 am

Re: Use html hyperlinks to navigate

Postby Nibo » Mon Oct 18, 2010 8:17 am

i use getIntent().getExtras() to get the string with the article content from the activity before.

Bundle getExtras()
Retrieves a map of extended data from the intent.

i can use the string replace to modify the links with a prefix but i have no idea how to invoke the same activity with the id
---------------------------------------------------------------------------------------------

19.10.10
if found a solution with a HTMLDialogTest tutorial
My solution:
Code: Select all

   protected TextView entryText;

   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      entryText = ((TextView) findViewById(R.id.Entry));
      entryText.setLinksClickable(true);
      entryText.setMovementMethod(LinkMovementMethod.getInstance());
...
      Spanned article = Html.fromHtml(content, image, null);
      setHTML(article);
}

   public void setHTML(Spanned html) {
      SpannableString message = new SpannableString(html.toString());
      Object[] spans = html.getSpans(0, html.length(), Object.class);
      for (Object span : spans) {
         int start = html.getSpanStart(span);
         int end = html.getSpanEnd(span);
         int flags = html.getSpanFlags(span);
         if (span instanceof URLSpan) {
            URLSpan urlSpan = (URLSpan) span;
            span = new CallbackSpan(urlSpan.getURL());
         }
         message.setSpan(span, start, end, flags);
      }
      entryText.setText(message);
   }

   private final class CallbackSpan extends ClickableSpan {

      private String m_data;

      public CallbackSpan(String url) {
         m_data = url.substring(0);
      }

      public void onClick(View view) {
         onCallback(m_data);
      }

   }

   protected void onCallback(String data) {
      Bundle bundel = getIntent().getExtras();
      bundel.putString("content", getArticleByID(data.replace(".html", "")));
      this.onCreate(bundel);
   }

Nibo
Freshman
Freshman
 
Posts: 2
Joined: Fri Oct 15, 2010 4:02 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests