我嘗試開發一個小的Android應用程序,我使用片段功能。這裏是我的TAB3佈局:多個textview不顯示在線性佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/European_Central_Bank" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Türk Lirası: " />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dolar:" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Japon Yeni:" />
</LinearLayout>
這是Java的一部分:
public class Tab3Fragment extends Fragment {
private String turkishLira;
private String dollar;
private String japaneseMoney;
URL url;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myCreateView=(LinearLayout)inflater.inflate(R.layout.tab_frag3_layout, container, false);
getCurrencyInfo();
TextView textView1 = (TextView) myCreateView.findViewById(R.id.textView1);
TextView textView2 = (TextView) myCreateView.findViewById(R.id.textView2);
TextView textView3 = (TextView) myCreateView.findViewById(R.id.textView3);
textView1.setText(turkishLira);
textView2.setText(dollar);
textView3.setText(japaneseMoney);
return myCreateView;
}
getCurrencyInfo() {...}
}
的問題是隻在手機上顯示的第一個TextView的。如果我交換了第一個和第二個textview,這次顯示了第二個具有靜態內容的textview。 我錯過了什麼?我在getCurrencyInfo方法中沒有任何問題,我打印它的結果。 提前致謝。
你確定getCurrencyInfo返回正確的值嗎?怎麼樣嘗試textView1.setText(「這是一個測試」);並告訴我們結果? –
啊,你是對的我想。它現在打印第二個textview。然而我打印結果的功能。我會跟蹤錯誤。謝謝 –