この例では、フィルタ リスト ビューのコードを実装する必要があります。2 つのクラスを使用しています: Car.java
(Object Car を含む)、Classは Class をCarAdapter
拡張しBaseAdapter
ます。以下はコードの一部です:
車.java
public class Car {
public String title;
public int car_id;
public Car(String title,int car_id) {
this.title = title;
this.car_id = car_id;
}
}
CarAdapter.java
public class CarAdapter extends BaseAdapter {
private List<Car> mCarList;
private LayoutInflater mInflater;
public CarAdapter(List<Car> list, LayoutInflater inflater) {
mCarList = list;
mInflater = inflater;
}
@Override
public int getCount() {
return mCarList.size();
}
@Override
public Object getItem(int position) {
return mCarList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewItem item;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.prototype, null);
item = new ViewItem();
item.CarTitle = (TextView) convertView
.findViewById(R.id.TextViewPrototype);
convertView.setTag(item);
} else {
item = (ViewItem) convertView.getTag();
}
Car curCar = mCarList.get(position);
item.CarTitle.setText(curCar.title);
return convertView;
}
private class ViewItem {
TextView CarTitle;
}
}
CarActivity.java
public class ActivityCar extends Activity {
private List<Car> mCarList;
private EditText et;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.car);
// Obtain a reference to the product catalog
mCarList = CarHelper.getCar(getResources());
// Create the list
ListView listViewCatalog = (ListView) findViewById(R.id.list_car);
listViewCatalog.setAdapter(newCarAdapter(mCarList,getLayoutInflater)));
}
}
ご協力ありがとうございました。