-1
私はSMSアプリケーションを構築しており、会話フラックスをリストビューに表示しています。 私のデータは、私のアプリケーションのSMSメッセージアイテムを参照するために作成したクラスのArrayListに登録されます。カスタムオブジェクトのArraylistからBaseAdapterを作成する
は、テスト目的のために、私はこのアダプタを作りました:
ここpackage fr.nf.smsplus;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.List;
/**
* Created by Nicolas on 20/05/2016.
*/
public class conversationAdapter extends BaseAdapter {
Context context;
Message[] conv;
private static LayoutInflater inflater = null;
public conversationAdapter(Context context, Message[] conv) {
// TODO Auto-generated constructor stub
this.context = context;
this.conv = conv;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return conv.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return conv[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
if (vi == null)
vi = inflater.inflate(R.layout.item_bubble_me, null);
TextView text = (TextView) vi.findViewById(R.id.txtMsg);
text.setText(conv[position].content);
return vi;
}
}
は私が作ったものの出力です:
私のアダプタが機能しています。しかし、今私のアダプタのgetViewで使用するバブルを選択する必要があるので、私はArrayAdapterを使用することはできません。私は自分のアダプターを作る必要があります。
so アレイのressourceの動的割り当てを行うには、配列の代わりにすべてをメッセージのArrayListに変換する必要があります。
メッセージのArrayListを正しく使用してリストビューに適用するには、アダプタを変更するにはどうすればよいですか?
これは、ありがとう –