未找到搜索结果时,如何显示2个未找到结果文本?在Android中
我的主xml文件中有2个未找到搜索结果时,如何显示2个未找到结果文本?在Android中,android,listview,textview,Android,Listview,Textview,我的主xml文件中有2个textview和2个listview以及一个EditText 首先是“搜索”EditText, 然后是“工具”TextView, 然后是“工具”ListView, 然后是“文章”TextView, 然后是“文章”ListView 我想做的是显示“找不到工具的结果”当有人键入一个单词(即“test”)并且它在我的sql中不存在时,我想在我的工具部分显示它,在我的文章部分显示“找不到文章的结果” 我的主要问题是,当我运行项目时,文本视图之间有一个巨大的空间。 看起来像这样
textview
和2个listview
以及一个EditText
首先是“搜索”EditText
,
然后是“工具”TextView
,
然后是“工具”ListView
,
然后是“文章”TextView
,
然后是“文章”ListView
我想做的是显示“找不到工具的结果”
当有人键入一个单词(即“test”)并且它在我的sql中不存在时,我想在我的工具部分显示它,在我的文章部分显示“找不到文章的结果”
我的主要问题是,当我运行项目时,文本视图之间有一个巨大的空间。
看起来像这样
No Results Found in Tools
No Results Found in Articles.
我想要实现的输出是:
No Results Found in Tools
No Results Found in Articles
我尝试将listview的可见性设置为gone,但仍然不起作用。你能帮我吗
编辑:这是我的xml布局
<?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="@color/white"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/navbar_search"
android:paddingLeft="5dp" >
<ImageView
android:id="@+id/buttonBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/btn_back" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/violet"
android:padding="5dp" >
<EditText
android:id="@+id/editTextSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_search"
android:paddingLeft="35dp" >
</EditText>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextSearch"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:src="@drawable/search" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/blue"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<TextView
android:id="@+id/textArticlesResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="@string/label_articles"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:textStyle="bold" />
<ListView
android:id="@+id/listViewArticlesResult"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/textArticlesResult"
android:cacheColorHint="@color/white"
android:fadeScrollbars="false" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/blue"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<TextView
android:id="@+id/textToolsResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="@string/label_tools"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_below = "@id/listViewArticlesResult" />
<ListView
android:id="@+id/listViewToolsResult"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/textToolsResult"
android:cacheColorHint="@color/white"
android:fadeScrollbars="false" >
</ListView>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="46dp" >
<ImageView
android:id="@+id/tabHome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="fitXY"
android:src="@drawable/tab_home_unselected" />
<ImageView
android:id="@+id/tabFb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="fitXY"
android:src="@drawable/tab_fb_unselected" />
<ImageView
android:id="@+id/tabSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="fitXY"
android:src="@drawable/tab_search_selected" />
<ImageView
android:id="@+id/tabFaves"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="fitXY"
android:src="@drawable/tab_myfaves_unselected" />
<ImageView
android:id="@+id/tabSettings"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="fitXY"
android:src="@drawable/tab_settings_unselected" />
</LinearLayout>
</LinearLayout>
检查您的代码:`
<TextView
android:id="@+id/textArticlesResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="@string/label_articles"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:textStyle="bold" />
<ListView
android:id="@+id/listViewArticlesResult"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/textArticlesResult"
android:cacheColorHint="@color/white"
android:fadeScrollbars="false" >
</ListView>
</RelativeLayout>`
`
替换为:
<TextView
android:id="@+id/textArticlesResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="@string/label_articles"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/blue"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:visibility="visible" >
<ListView
android:id="@+id/listViewArticlesResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="@color/white"
android:fadeScrollbars="false"
android:visibility="visible" >
</ListView>
</RelativeLayout>
并修改RelativeLayout的android:visibility
,它封装了您的ListView
code/XML(取决于搜索结果的显示方式),我不会说这是Eclipse问题。