开发者

Android - make whole area hyperlinked instead of just text?

Would really appreciate some help with this.

I have an app which consists of a gallery, text and icons. What i want to do is similar to the android market (example can be seen below). In the android market a whole area is hyperlinked rather than just the text. Hold your finger on one of the apps and it will light up green. That whole area is a hyperlink. Like below:

Looking to get something like this: http://img269.imageshack.us/img269/691/09dro开发者_StackOverflowid3295x440.jpg

Is there anyway i can do that to my app? I have a very similar app, the gallery is right at the top with icons down the left and text besides each icon. I'm a bit of a newbie so i'm using nested linearlayouts with textviews and imageviews in each one.

Is there a way that it can be done? Thanks for any help in advance!


As i misunderstood the question i'll give the correct answer here. If i understand right, you want to have an clickable View (in this case a LinearLayout) :

LinearLayout layout = (LinearLayout)findViewById(R.id.layoutId);

layout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });

Or any view for that matter (could be a Button, TextView, etc).


you could do the following to achieve this:

Spannable spans = (Spannable) text;
ClickableSpan clickSpan = new ClickableSpan() {
    @Override
    public void onClick(View widget) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://"
               + url));
    }

    public void updateDrawState(TextPaint ds) {
        // override link-centric text appearance
    }
};
int index = (text.toString()).indexOf(url);
spans.setSpan(clickSpan, index, url.length() + index, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Where text is your CharSequence.


Link not working

To answer ur query, create the link on the layout rather than text

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜