【发布时间】:2013-09-17 18:07:45
【问题描述】:
我打开一个对话框,当我选择任何一个时,有两个选项按钮,下面的布局应该更改是屏幕截图
现在下面有 list.xml 文件,其中有两个线性布局
english(即英语-泰卢固语列表)先显示英文单词,然后显示泰卢固语单词
<LinearLayout
android:id="@+id/engRowOfList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:orientation="vertical" >
<TextView
android:id="@+id/txtEng"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:textColor="#000000"
android:textSize="22dip"
android:textStyle="bold" />
<com....TextView
android:id="@+id/txtGuj"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:textColor="@color/orange"
android:textSize="22dip"
android:textStyle="bold"
lht:ttf_name="fonts/telugu.ttf" />
</LinearLayout>
泰卢固语(首先显示泰卢固语单词,然后显示英文单词
<LinearLayout
android:id="@+id/teluguRowOfList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:orientation="vertical" >
<com......GujTextView
android:id="@+id/txtEng"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:textColor="#000000"
android:textSize="22dip"
android:textStyle="bold"
lht:ttf_name="fonts/telugu.ttf" />
<TextView
android:id="@+id/txtGuj"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:textColor="@color/orange"
android:textSize="22dip"
android:textStyle="bold" />
</LinearLayout>
正如许多人建议的那样,您可以通过 LinearLayout.GONE/LinearLayout.VISIBLE 来做,所以我在下面的代码中尝试过,但仍然无法做到,下面是我的代码
scAdapter = new SimpleCursorAdapter(getApplicationContext(),
R.layout.list, cursor, new String[] { Const.ENGLISH,
Const.TELUGU }, new int[] { R.id.txtEng,
R.id.txtTelugu });
scAdapter.setViewBinder(new ViewBinder() {
public boolean setViewValue(View view,
android.database.Cursor cursor, int columnIndex) {
engListView = (LinearLayout) view.findViewById(R.id.engList);
teluguListView = (LinearLayout) view.findViewById(R.id.teluguList);
if (flagEnFl) { //flag for ENGLISH / TELUGU
engListView.setVisibility(LinearLayout.GONE); ***//HERE I AM GETTING NULLPOINTEREXCEPTION EVERY TIME***
teluguListView.setVisibility(LinearLayout.VISIBLE);
} else {
engListView.setVisibility(LinearLayout.VISIBLE);
teluguListView.setVisibility(LinearLayout.GONE);
}
任何人都可以帮助我如何处理这种情况
【问题讨论】:
-
当用户选择任何选项时,为什么不只创建一个布局并更改文本视图的内容..
-
但是当我更改 textview 的内容时,Armaan(英文文本无法正确显示,例如当我选择“@+id/txtGuj”时,当我放置英文文本时,英文文本将不会显示正确:(*
-
可能是因为您使用了泰卢固语的 ttf 字体。所以我认为你必须根据选项选择在运行时更改字体。
-
当有英语泰米尔语时,将字体设置为 tamil.ttf,当有泰米尔语英语时,将字体设置为任何英文字体,如 verdana.ttf。这样它就可以工作了。
-
非常感谢 Armaan 给了我很好的建议 :) 但是你知道我如何在运行时设置属性 lht:ttf_name="fonts/telugu.ttf" 吗??
标签: android android-layout layout view android-view