如果字符串中没有文本,则删除TextView空间-Android

如果字符串中没有文本,则删除TextView空间-Android,android,listview,layout,textview,Android,Listview,Layout,Textview,如果没有文本提供给TextView,那么布局中的TextView占据的区域会被删除,因此文本所在的区域不会出现空白,以便其他内容可以使用 在这里,您可以看到一个空白,信息将在“2013年9月17日”下显示,但如果我想删除该空间,使布局看起来更好,但仍有文本视图可用于其他部分,因为布局如何实现。上面看到的布局是ListView的一部分,因此如果我刚刚删除了TextView,如果日期部分下有信息,它将不会显示。信息是从internet上托管的XML文件接收的。对不起,我解释得很糟糕 联机托管的XM

如果没有文本提供给TextView,那么布局中的TextView占据的区域会被删除,因此文本所在的区域不会出现空白,以便其他内容可以使用

在这里,您可以看到一个空白,信息将在“2013年9月17日”下显示,但如果我想删除该空间,使布局看起来更好,但仍有文本视图可用于其他部分,因为布局如何实现。上面看到的布局是ListView的一部分,因此如果我刚刚删除了TextView,如果日期部分下有信息,它将不会显示。信息是从internet上托管的XML文件接收的。对不起,我解释得很糟糕

联机托管的XML文件:

<games_list>
<game>
<id>1</id>
<title>Grand Theft Auto 5</title>
<date1>17th September 2013</date1>
<date2/>
<date3/>
<platforms>360, PS3</platforms>
<thumb_url>
http://launchpadsoftware.webs.com/ReleaseDates%20Web%20Data/gta5thumb.jpg
</thumb_url>
</game>
<game>
<id>2</id>
<title>Grand Theft Auto 5</title>
<date1>17th September 2013</date1>
<date2/>
<date3/>
<platforms>360, PS3</platforms>
<thumb_url>
http://api.androidhive.info/music/images/eminem.png
</thumb_url>
</game>
</games_list>

1.
侠盗猎车手5
2013年9月17日
360,PS3
http://launchpadsoftware.webs.com/ReleaseDates%20Web%20Data/gta5thumb.jpg
2.
侠盗猎车手5
2013年9月17日
360,PS3
http://api.androidhive.info/music/images/eminem.png
list_row.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_card"
android:orientation="horizontal"
android:padding="5dip" >

<!--  ListRow Left sied Thumbnail image -->
<ImageView
    android:id="@+id/list_image"
    android:layout_width="50dip"
    android:layout_height="50dip"
    android:src="@drawable/gta5thumb"
    android:padding="3dip"
    android:background="@drawable/image_bg"
    android:layout_centerVertical="true"/>





<!-- Title Of Song-->
<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@id/list_image"
    android:layout_toRightOf="@id/list_image"
    android:text="Grand Theft Auto 5"
    android:textColor="#040404"
    android:textSize="18sp"
    android:layout_marginLeft="4dp"
    android:textStyle="bold"/>

<!-- Artist Name -->
<TextView
    android:id="@+id/date1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/title"
    android:textColor="#343434"
    android:textSize="14sp"
    android:layout_marginTop="1dip"
    android:layout_toRightOf="@id/list_image"
    android:layout_marginLeft="4dp"
    android:text="17th September 2013" />
<TextView
    android:id="@+id/date2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/date1"
    android:textColor="#343434"
    android:textSize="14sp"
    android:layout_marginTop="1dip"
    android:visibility="visible"
    android:layout_marginLeft="4dp"
    android:layout_toRightOf="@id/list_image"
    android:text="17th September 2013" />
<TextView
    android:id="@+id/date3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#343434"
    android:textSize="14sp"
    android:layout_marginLeft="4dp"
    android:text="17th September 2013"
    android:layout_below="@+id/date2"
    android:layout_toRightOf="@+id/list_image"/>

<!-- Rightend Duration -->
<TextView
    android:id="@+id/platforms"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@id/title"
    android:gravity="right"
    android:text="360, PS3"
    android:layout_marginRight="3dip"
    android:textSize="12sp"
    android:textColor="#10bcc9"
    android:textStyle="bold"/>

 <!-- Rightend Arrow -->    
 <ImageView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/arrow"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"/>

</RelativeLayout>

在自定义列表适配器中,应该隐藏没有文本的文本视图

textview.setVisibility(View.GONE)

在xml中,您应该使用

android:layout\u centerVertical=“true”


对于包含文本的文本视图。

我想您将动态地执行此操作,因此您可以在代码中执行此操作,只需将“可见性”设置为“消失”

textView.setVisible(View.GONE);

但它是ListView的一部分,因此如果我隐藏该TextView,则稍后添加的其他部分将不可见。可以告诉它是可见的还是从internet上的XML文件中消失了吗?我已将联机XML文件的布局添加到我的问题中。同时发布您在listview中使用的自定义行布局的代码。我已添加了我正在使用的自定义行布局。我是否可以通过适配器进行设置。例如,在我的适配器中,我使用这个date2.setText(song.get(CustomizedListView.KEY_date2));要设置每个TextView的文本,我可以使用XML文件来指定它是否应该隐藏吗?在适配器中,您也可以使用,但在此之前放一个if语句,以便检查是否要显示下一个TextView