小さなAndroidアプリを作成しています。私は、複数の部分をクリックしてテキストビューにテキストを表示したいと思います。Android複数のクリック可能な文字列をテキストビューで表示
最後に、複数のスパンを1つのテキストビューに表示する方法を調べましたが、残念ながらonClickメソッドは機能しません。単に何も起こらず、logcatの行さえありません。
私はこのような何かをしている:
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);
...
テキストが細かい下線が引かれているが、私はそれらをクリックすると、何も起こりません。 これは、関連性があるとは思われませんが、TableViewの一部です。それが何もしない理由がありますか?何が欠けていますか?それとも全く別のやり方でやるべきなのでしょうか?
ありがとうございます。
<?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のレイアウトを以下に示します:
<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>
を処理するために作りますか? – Noundla
確かに、ここでは、更新された質問に行きます。 – skandigraun
これをtrueに変更してください... android:textIsSelectable = "true" – Noundla