2012-05-01 4 views
0

내 문제는 내 listView 내 레이아웃의 모든 항목을 반복한다는 것입니다. 이 listView의 맨 아래에 편집 텍스트와 버튼이 있어야합니다. 하지만 여기에서는 listView의 각 행에 대해 텍스트와 버튼 편집이 반복되며 이유를 알지 못합니다. 누군가가 나를 도울 수 있다면 활동 :Android : 버튼 및 텍스트 편집 listView에서 반복

public class MessActivity extends ListActivity 
{ 
    public Channel chan; 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setListAdapter(Network.getInstance().Messages); 
     Bundle b = getIntent().getExtras(); 
     this.chan = (Channel) b.get("chanSelected"); 
     //add all message of selected chan to the messAdapter 
     for (int i = 0 ; i < this.chan.getListMessage().size() ; i++) { 
      Message mess = this.chan.getListMessage().get(i); 
      Network.getInstance().addMessage(mess); 
     } 
     setContentView(R.layout.mess_list); 
    } 
} 

어댑터를 :

public class MessageAdapter extends ArrayAdapter<Message> 
{ 
    private Context context; 
    private int textViewResourceId; 

    public MessageAdapter(Context context, int textViewResourceId) 
    { 
     super(context, textViewResourceId); 
     this.context = context; 
     this.textViewResourceId = textViewResourceId; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) 
    { 
     View row = convertView; 
     MessHolder holder = null; 
     //row null 
     if(row == null) 
     { 
      LayoutInflater inflater = ((Activity)context).getLayoutInflater(); 
      row = inflater.inflate(textViewResourceId, parent, false); 

      holder = new MessHolder(); 
      holder.texte = (TextView)row.findViewById(R.id.listMess); 

      row.setTag(holder); 
     } 
     else 
     { 
      holder = (MessHolder)row.getTag(); 
     } 

     Message mess = getItem(position); 
     holder.texte.setText(mess.getText()); 

     return row; 
    } 

    static class MessHolder 
    { 
     TextView texte; 
    } 
} 

레이아웃 :

<?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="wrap_content" 
    android:orientation="vertical" > 
    <ListView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:id="@android:id/list"> 
    </ListView> 

      <TextView 

      android:id="@+id/listMess" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center" 
      android:padding="10dp" 
      android:textSize="16sp" > 

     </TextView> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="bottom" > 


     //edittext 
     <EditText 
      android:id="@+id/editText1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:ems="10" 
      android:inputType="text" /> 




     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:text="Envoyer" /> 

    </LinearLayout> 

</LinearLayout> 

당신의 도움에 감사드립니다.

답변

1

ListView 방법 addFooter(View v)을 사용하십시오.

이보기에 대한 XML 레이아웃을 정의하고 팽창 할 수

ListView lv = getListView(); 
LayoutInflater inflater = getLayoutInflater(); 
View footer = (View)inflater.inflate(R.layout.footer, lv, false); 
lv.addFooterView(footer, null, false); 
+0

좋아, 내가 시도 할 것이다. 하지만 addFooterView 대신 머리글이 있다고 생각하십니까? – user1364017

+0

죄송합니다. – skywall

+0

도와 주셔서 감사합니다. 시도했지만 바닥 글이 목록보기에 나타나지 않습니다. – user1364017

0

는 첫째로이 문제의 원인은 목록보기는 볼 때 스크롤을 다시 사용됩니다, 그래서 우리는 그것을 관리하는 우리의 GET보기에서 논리를 가지고 있어야

다시 사용할 해달라고 경우
if(convertview == null) 
{ 
//code here 
}else { 
//code here 
}  

,하지만 당신은 다음과 같은 사용할 수 있습니다

@Override 
    public int getItemViewType(int position) { 
    return position; 
} 

@Override 
public int getViewTypeCount() { 
    return 500; 
} 
관련 문제