よ、
private class MyGriAdapter extends BaseAdapter{
ArrayList<Doctor> data;
public MyGriAdapter(ArrayList<Doctor> data){
this.data = data;
}
@Override
public int getCount() {
return data.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView vv = new TextView(getApplicationContext());
vv.setTextColor(Color.BLACK);
vv.setText(data.get(position).firstname);
return vv;
}
@Override
public Object getItem(int arg0) {
return data.get(arg0);
}
@Override
public long getItemId(int position) {
return position;
}
}
と私のボタンクリックイベントでありますその後、アイテム、およびその項目を膨らませるためのアダプタを使用し、それは中身だ変更:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null){
// Create new view
LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.item, parent, false);
}
// Set information
TextView titleView = (TextView)convertView.findViewById(R.id.title);
titleView.setText(data.get(position).title);
TextView otherView = (TextView)convertView.findViewById(R.id.other);
titleView.setText(data.get(position).other);
return convertView;
}
convertViewがnullの場合は、あなたが新しいものを作成し、すべての場合には、あなたがそのビューを再利用します。 XMLのレイアウトはこのようなものが考えられます。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/title" android:layout_width="fill_parent"
android:layout_height="match_parent" />
<TextView android:id="@+id/other" android:layout_width="fill_parent"
android:layout_height="match_parent" />
</LinearLayout>
これはさらに、インフレータの参照を保持し、インナービューを追跡するために、ビューのタグシステムを使用して最適化することができ、それは少しオフトピックです。..さらに詳しく知りたい場合は、Google IO Conferenceをお勧めします。World of ListView
ビューの作成にアプリケーションコンテキストを使用しないでください。それはあなたのテーマや他のものに問題を引き起こします。 – adamp