在TextView中的问题android

问题描述:

嗨,我所有我做一个示例应用程序。为更新列表。 我有一个列表类,它的xml就像。在TextView中的问题android

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<ListView android:id="@+id/ListView01" android:layout_height="wrap_content" 
android:layout_width="fill_parent"></ListView> 
<TextView android:id="@+id/more" 
android:layout_height="wrap_content" 
android:text="Click to view more..." 
android:textStyle="normal|bold" android:textColor="#FF8000"  android:textSize="10dip" 
android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent"> 
</TextView> 
</LinearLayout> 

现在我已经设定的文本视图TouchListener和下面的代码添加它

@Override 
     public boolean onTouch(View v, MotionEvent event) { 
     switch(v.getId()) 
     { 
     case R.id.more: 
     //update List Method Call.. 
     more.setText("Click to view More.."); 
     adapter.notifyDataSetChanged(); 
     } 

     // TODO Auto-generated method stub 
     return false; 
    } 

您对我已经添加

more.setText("Click to view More.."); 

线switch语句的3号线看到,当我的列表更新。文本视图不再显示在底部。 请引导我为什么这发生在我身上,最新的解决方案?

+0

在开始你的TextView是显示在列表的底部..? – 2011-05-16 05:30:04

+0

是在开始显示。但当它列表得到update.it消失 – Shah 2011-05-16 05:33:35

+0

并在开始listview有任何数据。? – 2011-05-16 05:38:08

使用下面的代码.. footer_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:paddingTop="7dip" 
android:paddingBottom="7dip" 
android:orientation="horizontal" 
android:gravity="center"> 
<LinearLayout 
android:id="@+id/footer_layout" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:gravity="center" 
android:layout_gravity="center"> 

<TextView 
    android:text="footer_text_1" 
    android:id="@+id/footer_1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="14dip" 
    android:textStyle="bold" 
    android:layout_marginRight="5dip"> 
</TextView> 

</LinearLayout> 
    </LinearLayout> 

,并使用以下代码:

public class listactivty extends ListActivity{ 
private Context context = null; 
private ListView list = null; 

public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
    list = (ListView)findViewById(android.R.id.list); 
//code to set adapter to populate list 

View footerView = 
     ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false); 
    list.addFooterView(footerView); 
} 

使用了单独的ListView XML文件..

感谢 沙贾汗·艾哈迈德

尝试android:layout_height="fill_parent" android:layout_above="@+id/more"ListView。现在,即使你的ListView增长,它也不会隐藏TextView

UPDATE

<RelativeLayout android:id="@+id/relativeList" 
    android:orientation="horizontal" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/LinearBottom3"> 
    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:id="@+id/chathlist" 
    /> 
</RelativeLayout> 

    <RelativeLayout android:id="@+id/LinearBottom3" 
    android:orientation="horizontal" android:layout_width="fill_parent" 
    android:layout_height="wrap_content"><!--Make it as center--> 
    <TextView android:id="@+id/more" android:layout_height="wrap_content" 
android:text="Click to view more..." android:textStyle="normal|bold" android:textSize="10dip" 
    android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent"/> 
    </ReletiveLayout> 
+0

你的意思,我需要实现LinearLayout instaead的线性? – Shah 2011-05-16 05:41:35

+0

仍然没有为我工作 – Shah 2011-05-16 05:45:47

+0

是啊你需要relativelayout ..这对我来说工作得很好。 – Hussain 2011-05-16 06:53:24

试试这个...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<ListView android:id="@+id/ListView01" android:layout_width="fill_parent" android:layout_alignParentTop="true" android:layout_height="fill_parent" android:layout_above="@+id/more"></ListView> 
<TextView android:id="@+id/more" 
android:layout_height="wrap_content" 
android:text="Click to view more..." 
android:textStyle="normal|bold" android:textColor="#FF8000"  android:textSize="10dip" 
android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent" android:layout_alignParentBottom="true"> 
</TextView> 
</RelativeLayout> 
+0

糟糕...没有成功然而,与此同时。这里显示我的检视首,但是当我点击它是空白 – Shah 2011-05-16 05:46:45

+0

让我告诉你的代码.. – 2011-05-16 05:51:12

+0

上述的代码是整个代码。并具有//更新列表方法调用中的一部分。这 将与我的更新列表查看项目 – Shah 2011-05-16 05:55:35

,你可以在这种情况下使用列表页脚。

将此代码添加到您的Java文件中。并在您的列表中动态添加页脚。

TextView more = new TextView(this); 
more.setText("Click to view more..."); 
more.setClickable(true); 
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(width, Height); 
more.setLayoutParams(params); 

more.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) { 
     //update List Method Call.. 
      more.setText("Click to view More.."); 
      adapter.notifyDataSetChanged(); 
    } 
}); 

ListView listView = (ListView) findViewById(R.id.ListView01); 
listView.addFooterView(more); 

这可以帮助你。

+0

设置可点击文本视图 - 更多和设置对齐 – 2011-05-16 06:01:31

+0

什么是getListView ?? – Shah 2011-05-16 06:10:54

+0

plz检查我的编辑答案。 – 2011-05-16 06:26:54

试试这个.. footer.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="wrap_content"> 

    <TextView android:layout_height="wrap_content" 
     android:textSize="30dip" android:gravity="center_horizontal" 
     android:text="Click to view More.." android:layout_width="fill_parent" 
     android:id="@+id/more"></TextView> 

</LinearLayout> 

类文件

LayoutInflater inflater = activity.getLayoutInflater(); 
LinearLayout footer = (LinearLayout)inflater.inflate(
      R.layout.footer, null); 
TextView more= (TextView)footer.findViewById(R.id.more); 



more.setOnClickListener(new View.OnClickListener() 
     { 
      @Override 
      public void onClick(View v) 
      { 
       //List Update Code 
      } 
     });