2 zy503816801 zy503816801 于 2013.09.12 16:56 提问

这个搜索功能怎么实现呀?求大神帮忙指点,谢谢!下面是代码

主程序的:
public class MainActivity extends Activity {
private ListView listview;
private MedicineService medicineservice;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
medicineservice = new MedicineService(this);

    listview = (ListView) this.findViewById(R.id.listview);
    Button button = (Button)findViewById(R.id.mybutton);
    button.setOnClickListener(new ButtonClickListener());


}
public class ButtonClickListener implements View.OnClickListener{
EditText txt = (EditText) findViewById(R.id.myEdit);
private String qwe = txt.getText().toString(); 
public void onClick(View v) {
    List<Medicine> medicines = medicineservice.getScrollData(0, 10);
    medicineservice.find(this.qwe);
    MedicineAdapter adapter = new MedicineAdapter(this, medicines, R.layout.item);
    List<HashMap<String,Object>> data = new ArrayList<HashMap<String,Object>>();
    for(Medicine medicine : medicines){
        HashMap<String,Object> item = new HashMap<String,Object>();
        item.put("name", medicine.getName());
        item.put("ename", medicine.getEname());
        item.put("content", medicine.getContent());
        item.put("id", medicine.getId());
        data.add(item);
    }
    //SimpleAdapter adapter = new SimpleAdapter(this,data,R.layout.item,new String[]{"name","ename","content"}, new int[]{R.id.name,R.id.ename,R.id.content});
    listview.setAdapter(adapter);
}

public LayoutInflater getSystemService(String layoutInflaterService) {

    return null;
}
}

}

自定义适配器的:
public class MedicineAdapter extends BaseAdapter {
private List medicines;//绑定的数据
private int resource;//绑定的界面
private LayoutInflater inflater;
public MedicineAdapter(ButtonClickListener buttonClickListener,List medicines,int resource ) {
this.medicines = medicines;
this.resource = resource;
inflater = (LayoutInflater) buttonClickListener.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public int getCount() {
    return medicines.size();//得到总数
}

public Object getItem(int position) {
    return medicines.get(position);
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    if(convertView==null){
        convertView = inflater.inflate(resource, null);
    }
    TextView nameView = (TextView) convertView.findViewById(R.id.name);
    TextView enameView = (TextView) convertView.findViewById(R.id.ename);
    TextView contentView = (TextView) convertView.findViewById(R.id.content);
    Medicine medicine = medicines.get(position);
    //下面代码实现数据绑定
    nameView.setText(medicine.getName());
    enameView.setText(medicine.getEname());
    contentView.setText(medicine.getContent());
    return convertView;
}

}

public LayoutInflater getSystemService这个该怎么写???谢谢各位大神。

Csdn user default icon
上传中...
上传图片
插入图片