2011-05-16 9 views
0

salut tous je fais un exemple d'application. pour mettre à jour la liste. J'ai une classe de liste et son xml est comme.problème dans TextView dans 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> 

maintenant j'ai mis TouchListener de vue texte et a ajouté le code suivant dans ce

@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; 
    } 

Vous voyez sur la 3ème ligne de l'instruction switch i ai ajouté

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

ligne, mais quand ma liste est mise à jour. Le texte Afficher n'est plus visible dans le bas. S'il vous plaît Guide mon pourquoi cela m'arrive et quelle est la solution ??

+0

à commencer votre textview était exposée au bas de la liste ..? –

+0

oui au début il s'affiche. mais quand la liste a eu update.it disparaît – Shah

+0

et au début listview avoir des données. –

Répondre

0

utiliser le code suivant .. 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> 

et utilisez les touches suivantes dans le code:

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); 
} 

utilisation du fichier XML séparé pour ListView ..

Merci Shahjahan Ahmad

1

essayez android:layout_height="fill_parent" android:layout_above="@+id/more" dans le ListView. Maintenant, même si votre ListView pousse, il ne cache pas le TextView.

MISE À JOUR

<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

vous voulez dire et je dois mettre en œuvre RelativeLayout instaead de Linear one ?? – Shah

+0

Toujours pas travaillé pour moi – Shah

+0

Ouais, vous avez besoin du relativelayout .. Cela fonctionne très bien pour moi. – Hussain

1

essayer ...

<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

Oops ... Pas encore réussi Mais avec celui-ci aussi.il me montre la vue d'abord, mais quand je clique dessus, il est vide – Shah

+0

laissez-moi montrer votre code .. –

+0

Le code ci-dessus indiqué est l'ensemble du code. et la partie qui a // mettre à jour la liste Méthode Appeler .. sera remplacé par ma méthode de mise à jour Liste Afficher articles – Shah

2

vous pouvez utiliser le pied de page de liste dans ce cas.

Ajoutez ce code dans votre fichier java. et ajoutez le pied de page dynamiquement dans votre liste.

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); 

cela peut vous aider.

+0

jeu cliquez sur la vue du texte - plus et définir l'alignement –

+0

what is getListView ?? – Shah

+0

plz vérifier ma réponse éditée –

1

try this .. 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> 

dans le fichier de classe

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 
      } 
     });