我有一個細節片段,我有幾個項目,主要是TextView。我也有一個CursorLoader,onLoadFinished應該在佈局中設置所有這些值。Android xml佈局項目不更新
例如,在這個片段中,它打印出的文本被設置爲我從ContentProvider的
收到String dur = this.expected_duration + " " + this.durationUnit;
Log.v(LOG_TAG, "SETTING DURATION " + dur);
if(dur != null || !"".equals(dur)) {
if(durationTextView != null) {
Log.v(LOG_TAG, "SETTING TEXT VIEW " + dur);
durationTextView.setText(dur);
}
}else{
Log.v(LOG_TAG, "FAIL SETTING TEXT VIEW " + dur);
}
我在日誌中看到結果的價值,但這樣的結果是永遠得到實際的TextView。
我知道一個事實,它不是一個知名度或文字字體的問題。我將TextView突出顯示爲粉紅色,並確保模擬文本顯示在屏幕上。我有一種感覺,我可能會創建一個重疊的片段(不知道它是否可能)。我可以很好地實例化所有TextView並提取所有值,但不能將它們放在屏幕上。請幫忙。另外,如果我的重複片段理論是正確的,請解釋你如何追蹤它。謝謝。
我的佈局文件(以防萬一)
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jennyeckstein.udacitycoursepicker.DetailActivityFragment"
>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/course_subtitle"
tools:text="How to Make an Android App"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/course_layout_detail"
android:layout_below="@id/course_subtitle"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/duration"
android:background="@color/pink"
android:textSize="16sp"
tools:text="333 years"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/course_level"
tools:text="ADVANCED"/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/begin_course_button"
android:text="Go to Udacity"
android:layout_below="@+id/course_layout_detail"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/required_knowledge"
android:layout_below="@id/begin_course_button"
tools:text="If you are new to programming and don’t know where to start"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/required_knowledge"
android:id="@+id/summary"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/summary"
android:background="@color/green"
android:id="@+id/syllabus"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/syllabus"
android:id="@+id/faq"/>
</RelativeLayout>
</ScrollView>
</FrameLayout>
源代碼上GitHub Repo
佈局名稱:fragment_detail.xml和 片段名稱:DetailActivityFragment.java
@John_Shea,thanx這麼多,我完全錯過了它,你的解決方案完全工作。我正在通過代碼和它的佈局,失敗了我!做得好! – Jenny