的TextView的android系统中设置的知名度不工作 [英] Set visibility of TextView in android not working

查看:142
本文介绍了的TextView的android系统中设置的知名度不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序运行到一个运行时异常时,我尽量让视图GONE。
我的code处理的:

My program runs into a runtime exception when I try to make the view 'GONE'. My code that handles it:

setContentView(R.layout.list_main);
... 
 lv =  getListView();
             View header = (View) findViewById(R.id.header_layout_root);
             TextView tv = (TextView) header.findViewById(R.id.new_highscore);
            tv.setVisibility(View.GONE);

 lv = getListView();
        LayoutInflater inflater = getLayoutInflater();
        View header = inflater.inflate(R.layout.list_header, (ViewGroup) findViewById(R.id.header_layout_root));
        lv.addHeaderView(header, null, false);

mC = mDBHelper.getAllHighScores();
        startManagingCursor(mC);

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.row, mC, 
                new String[] { DBAdapter.COL_NAME, DBAdapter.COL_SCORE }, 
                new int[] { R.id.txtText1, R.id.txtText2 });
        lv.setAdapter(adapter);

XML:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/header_layout_root"
  android:background="#ffffff"
  android:orientation="vertical">
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Pick Master High Scores"
    android:background="#000000"
    android:textColor="#ffffff"
    android:textSize="28dp"
    android:gravity="center_horizontal"
    android:paddingTop="10dp"
    android:paddingBottom="10dp">
</TextView>
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     android:id="@+id/header_layout_root1">
    <ImageView
        android:id="@+id/sample_image"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/pickmaster"
        android:scaleType="fitXY">
    </ImageView>
    <TextView
        android:id="@+id/new_highscore"
        android:text="New High Score added!"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#ffffffff"
        android:textSize="12dp"
        android:background="#AA000000"
        android:padding="5dp"
        android:layout_alignParentLeft="true"
        android:layout_alignBottom="@id/sample_image">
    </TextView>
</RelativeLayout>

问题是,我认为,new_highscore不是list_main,但它是在另一个XML文件。我用两个,因为我有一个标题和图像等列表视图。

The problem is, I think, that new_highscore is not in list_main, but it is in another xml file. I am using two as I have a listview with a header and image etc.

这使得查看任何想法隐形或只是走了?

Any ideas on making the view 'invisible' or just 'gone'?

谢谢,

推荐答案

试试这个code

   lv = getListView();
   LayoutInflater inflater = getLayoutInflater();
   View header = inflater.inflate(R.layout.list_header, (ViewGroup) findViewById(R.id.header_layout_root));
   lv.addHeaderView(header, null, false);
   View relativeLayout = header.findViewById(R.id.header_layout_root1);
   TextView highScore = relativeLayout.findViewById(R.id.new_highscore);
   highScore.setVisibility(View.GONE);

从顶部删除此code

lv =  getListView();
View header = (View) findViewById(R.id.header_layout_root);
TextView tv = (TextView) header.findViewById(R.id.new_highscore);
tv.setVisibility(View.GONE);

如果还是不行,请把你所遇到的异常。

If that doesn't work, please post the exception your are encountering.

这篇关于的TextView的android系统中设置的知名度不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆