0

私の問題は、listView がレイアウトのすべての項目を繰り返すことです。この listView の下部に編集テキストとボタンが必要です。しかし、ここでは編集テキストとボタンが 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>

ご協力ありがとうございました。

4

2 に答える 2

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);
于 2012-05-01T10:36:29.360 に答える