久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Android textview中的多個可點(diǎn)擊字符串

Android Multiple clickable strings in textview(Android textview中的多個可點(diǎn)擊字符串)
本文介紹了Android textview中的多個可點(diǎn)擊字符串的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在創(chuàng)建一個小型 Android 應(yīng)用.我想在一個文本視圖中顯示一個文本,其中包含多個要單擊的部分.(每個都應(yīng)該顯示一些不同的信息)

I am creating a small Android app. I would like to display a text in a textview with multiple parts to click on. (Each should show some different message)

最后我設(shè)法找出如何在一個文本視圖中顯示多個跨度,但不幸的是 onClick 方法不起作用.根本沒有任何反應(yīng),甚至沒有 logcat 行.

Finally I managed to find out how to display mutiple spans in one textview, however unfortunately the onClick methods don't work. Simply nothing happens, not even a logcat line.

我有這樣的事情:

SpannableStringBuilder ssb=new SpannableStringBuilder();
ssb.append("first  second")

ssb.setSpan(new ClickableSpan() {
    @Override
    public void onClick(View v) {
    //Eredmeny2.this is just the context, name of the whole class
    Toast.makeText(Eredmeny2.this, "first", Toast.LENGTH_LONG).show();
    }
}, 1, 3, 0);

ssb.setSpan(new ClickableSpan() {
    @Override
    public void onClick(View v) {
    Toast.makeText(Eredmeny2.this, "second", Toast.LENGTH_LONG).show();
    }
}, 7, 10, 0);

TextView t1=new TextView(this);
t1.setText(ssb);
...

文本下劃線很好,但是當(dāng)我單擊它們時沒有任何反應(yīng).它是 TableView 的一部分,盡管我認(rèn)為這無關(guān)緊要.你有什么想法為什么它什么都不做嗎?我想念什么?還是我應(yīng)該以完全不同的方式來做?

The text is underlined fine, but nothing happens when i click them. It is a part of a TableView, although I do not think this is relevant. Do you have any ideas why it does not do anything? What do I miss? Or should I do it on some totally different way?

提前致謝.

此部分將使用的布局文件如下:

The layout file this part would use is the following:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
    android:id="@+id/ScrollView01"
    android:background="#FF0000">


    <TableLayout
        android:id="@+id/TableLayout01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:stretchColumns="0"
        android:showDividers="middle"
        android:padding="3dp">
    <TableRow
        android:id="@+id/TableRow01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/TextView01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="3dp"
            android:background="#000000"
            android:textColor="#FFFFFF"
            android:padding="6dp"
            android:text="Hour"
            android:textSize="20sp"
            android:textStyle="bold" >

        </TextView>
        <TextView android:id="@+id/TextView02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:textStyle="bold"
            android:text="Minute"
            android:padding="6dp"
            android:textColor="#FFFFFF"
            android:background="#000000">
        </TextView>

    </TableRow>

    </TableLayout>


</ScrollView>

而TextView直接使用的TextView布局如下:

And the TextView layout that the TextView uses directly is the following:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tv" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:background="#000000"
android:textIsSelectable="false"
android:textColor="#FFFFFF">
</TextView>

推薦答案

據(jù)我了解,您想讓 textview 的多個部分可點(diǎn)擊.

as i understand you want to make multiple part of textview clickable.

這段代碼對我有用!

SpannableString ss = new SpannableString("this is a text");
ss.setSpan(new myClickableSpan(1),0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new myClickableSpan(2),5, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new myClickableSpan(3),8, 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

mTextView.setText(ss);
mTextView.setMovementMethod(LinkMovementMethod.getInstance());

只需自定義 ClickableSpan 來處理點(diǎn)擊事件

just make custom ClickableSpan to handle the click event

public class myClickableSpan extends ClickableSpan{

    int pos;
    public myClickableSpan(int position){
        this.pos=position;
    }

    @Override
    public void onClick(View widget) {
        Toast.makeText(getApplicationContext(), "Position "  + pos + " clicked!", Toast.LENGTH_LONG).show();
    }

}

這篇關(guān)于Android textview中的多個可點(diǎn)擊字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产精品亚洲综合 | 国产精品视频一区二区三区不卡 | 亚洲视频免费在线 | 午夜国产一级片 | 国产成人免费视频网站高清观看视频 | 亚洲国产一区二区三区在线观看 | 国产高清精品在线 | 精品视频一区二区三区在线观看 | 国产精品毛片无码 | 日韩中文字幕一区二区 | 欧美一区二区三区四区视频 | 亚洲一区中文字幕在线观看 | 久久成人精品 | 亚洲成人精品 | 日韩欧美在线视频 | 日本中文字幕在线观看 | 午夜免费观看体验区 | 日韩中出| 一本色道精品久久一区二区三区 | 国产小视频在线 | 亚洲综合无码一区二区 | 国产亚洲精品久久久久久牛牛 | 免费看的黄网站 | 久www| 久久出精品 | 男人的天堂在线视频 | 亚洲成人免费视频在线 | 狠狠av| 免费一级黄色录像 | 99国产精品一区二区三区 | 四季久久免费一区二区三区四区 | 香蕉婷婷 | av片免费 | 中文字幕亚洲区一区二 | 毛片站 | 国产精品久久久久久中文字 | 99久久免费观看 | 欧美日韩综合 | 本道综合精品 | 看av在线 | 日本a在线|