2011-05-16 61 views
0

嗨,我所有我做一個示例應用程序。爲更新列表。 我有一個列表類,它的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

回答

0

使用下面的代碼.. 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文件..

感謝 沙賈汗·艾哈邁德

1

嘗試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

1

試試這個...

<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

2

,你可以在這種情況下使用列表頁腳。

將此代碼添加到您的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

1

試試這個.. 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 
      } 
     });