2013-02-09 93 views
5

我遇到了这个奇怪的问题,导致了我很多头痛和麻烦。当textIsSelectable设置为true时,Android TextView不会更新它的文本

我发布了一个应用程序,该应用程序是多本书的存储库,我决定使用TextView来显示每章的文本,因为它符合要求,而且使用起来很快且容易。

用户问他可以选择一个文本并复制它,我用textIsSelectable = true并且一切正常,第二天他打电话给我报告文本没有改变,你打开一章,然后切换到另一章章节,但文本保持不变。

我认为这可能是我的一些逻辑问题,但经过一些调试后,问题出现在TextView中,当我设置textIsSelectable = false;一切都很好。

为了确保我使用了每次显示文本时增加的静态int,文本保持不变。

那么问题是什么?我是否以错误的方式使用TextView?或者它是TextView本身的一些错误?

这是我的布局(txtBody是导致问题的TextView)

 <?xml version="1.0" encoding="utf-8"?> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/white"> 

    <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/scrollView" 
      android:fillViewport="true" 
      > 

     <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 

       android:orientation="vertical" 
       android:gravity="right"> 

      <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Title Text" 
        android:id="@+id/txtTitle" 
        android:textSize="24sp" 
        android:padding="5dp" 
        android:gravity="right"/> 

      <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Detail Text" 
        android:id="@+id/txtBody" 
        android:background="@android:color/white" 
        android:gravity="right" 
        android:textColor="@android:color/black" 
        android:textSize="16sp" 
        android:padding="5dp" 
        android:enabled="true" 
        android:textIsSelectable="true" 
        android:selectAllOnFocus="false" 
        android:soundEffectsEnabled="true"/> 

     </LinearLayout> 


    </ScrollView> 


</FrameLayout> 

我用这个代码来设置文本:

String body = MainDataManager.getInstance().getChapterBody(book.getTable(), chapter.getId()); 
    updateTextStyle(); 
    txtTitle.setText(chapter.getTitle()); 
    txtBody.setText(body, TextView.BufferType.SPANNABLE); 
+0

经过2〜3小时的实验,我发现这是原因。我恨我的时间是这样浪费的......对于我的谷歌搜索这个页面是第一次打击,第二次打击是[https://code.google.com/p/android/issues/detail?id=78491 ]描述完全符合我的情况。它在2014年以中等优先级被标记为BUG,并且在2016年还没有被固定为YET。这不是我第一次浪费我这样的时间...通过几年未修复的错误。 – 2016-03-02 18:58:45

回答

0

Uase无效()方法更改的文本前TextView中。

String body = MainDataManager.getInstance().getChapterBody(book.getTable(), chapter.getId()); 
    updateTextStyle(); 
    txtTitle.invalidate(); 
    txtTitle.setText(chapter.getTitle()); 
    txtBody.invalidate(); 
    txtBody.setText(body, TextView.BufferType.SPANNABLE); 
+0

但是,我必须在活动OnStart()或OnResume()方法中进行无效操作。 – Kumait 2013-03-20 08:26:37

+0

不幸的是,这个建议对我不起作用。 – meisteg 2013-04-28 14:43:40

+0

我错了,它也不适用于我 – Kumait 2013-05-18 08:19:32

相关问题