0

我正在打开一个对话框,其中有两个选项按钮,当我选择任何一个时,下面的布局应该更改是屏幕截图

在此处输入图像描述

现在有下面的 list.xml 文件,其中有两个线性布局

英语(这是英语-泰卢固语列表)首先显示英语单词然后显示泰卢固语单词

      <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);
            }

任何人都可以帮助我如何处理这种情况

4

4 回答 4

0

简单的解决方案

将两种布局合二为一,如下所示,然后制作VISIBLE它们GONE

<LinearLayout>
    <LinearLayout
     android:id="@+id/englishLayour>

    </LinearLayout>
   <LinearLayout
     android:id="@+id/englishLayour>

   </LinearLayout>

</LinearLayout>


radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if(checkedId==R.id.radioEnglish);
            {
                  englishLayout.setVisibility(View.VISIBLE);
                  tamilLayout.setVisibility(View.GONE);

            }else{
                  englishLayout.setVisibility(View.GONE);
                  tamilLayout.setVisibility(View.VISIBLE);              
            }
    });
于 2013-09-13T06:55:58.213 回答
0

将两个布局文件合并为一个。隐藏不应首先显示的视图。当用户从对话框中选择时,隐藏对话框并显示所需的视图。

于 2013-09-13T06:47:46.897 回答
0

尝试这个:

在您的活动中包含此子类:

public class Typefaces{

        private final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();

            public Typeface get(Context c, String name){
                synchronized(cache){
                    if(!cache.containsKey(name)){
                        Typeface t = Typeface.createFromAsset(
                                c.getAssets(), 
                                String.format("fonts/%s.ttf", name)
                            );
                        cache.put(name, t);
                    }
                    return cache.get(name);
                }
            }

        }

然后像这样实现:

Typefaces tf = new Typefaces();

tvMessage.setTypeface(tf.get(context, "shruti"));

不要忘记将 .ttf 文件添加到项目中的资产/字体文件夹中。(如果没有,请创建字体文件夹。)。并且字体文件名应该是小写的。在文件夹和课堂上。

希望能帮助到你!!

于 2013-09-13T07:05:00.440 回答
0

无法在运行时切换 2 布局。最好的解决方案是将 2 个不同的 LinearLayout 放在相同的布局中,并在用户做出决定时切换( View.VISIBLE / View.GONE )它们的可见性。

于 2013-09-13T08:10:03.277 回答