简体   繁体   中英

SetMovementMethods - ScrollingMovementMethod with LinkMovementMethod

I am new to Android Studio/Java.I have composed a script which creates a TextView contains a number of lines of information. I want to make each line clickable, to create a Toast dialog for example, which content relevant to that entry. This I can do.

I also want the TextView to be scrollable. I can do this too...... but NOT both.

I am guessing from what I have read that one command cancels the other. Here is the code I am trying to use. Is there another way to enable this?

responseTextView.setMovementMethod(new ScrollingMovementMethod()); responseTextView.setMovementMethod(LinkMovementMethod.getInstance()); responseTextView.setText(builder, TextView.BufferType.SPANNABLE);

I have found the answer by changing the activity_main.xml to place the TextView inside a ScrollView control.

<ScrollView android:visibility="visible"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:keepScreenOn="true"
android:scrollbarStyle="insideInset"
android:id="@+id/scrollView1"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnSearch" >

<TextView
    android:id="@+id/lblOutput"
    android:isScrollContainer="true"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbarStyle="outsideOverlay"
    android:scrollbars="vertical"
    android:text="Awaiting Results..."
    android:verticalScrollbarPosition="right"
    android:layout_gravity="top"
    android:keepScreenOn="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/btnSearch" />

</ScrollView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM