难以在大型自定义数据库列表视图中搜索

时间:2015-12-15 07:00:52

标签: android database listview search

我是一个新的Android编程。请抓住我的手! 我有一个很大的自定义列表视图,数据库已填充。 我在自定义列表视图中有两个Textview和一个Imageview。 这是我获取和设置的Model类:

    private int id;
private String name;
private String family;
private String img;

我的数据库类包含四个值:

public class DrListDatabase extends DatabaseAssets {

DrLists drLists;

public static String KEY_ID = "Id";
public static String KEY_NAME = "Name";
public static String KEY_FAMILY = "Family";
public static String KEY_IMG = "img";

我会在其他活动中搜索大列表视图中的项目。这是我在数据库类中的查询:

    public DrLists findProduct(String Title) {
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + KEY_NAME + " Like  '%" + Title + "%' or " + KEY_FAMILY +
            " Like '%" + Title +"%'" ;
    SQLiteDatabase db = this.getWritableDatabase();

    Cursor cursor = db.rawQuery(query, null);

drLists=new DrLists();

    if (cursor.moveToFirst()) {
        cursor.moveToFirst();
        drLists.setId(Integer.parseInt(cursor.getString(0)));
        drLists.setName(cursor.getString(1));
        drLists.setFamily(cursor.getString(2));
        cursor.close();
    } else {
        drLists = null;
    }
    db.close();
    return drLists;
}

这是我的Adapter类:

public class MyListAdapter extends ArrayAdapter<DrLists> {
LayoutInflater inflater;
Context m_context;
public MyListAdapter(Context context, int resource, List<DrLists> objects) {
    super(context, resource, objects);
    inflater = LayoutInflater.from(context);
    m_context = context;


}


@Override
public View getView(int position, View view, ViewGroup parent) {
    view = inflater.inflate(R.layout.dr_list, null);

    ImageView img = (ImageView) view.findViewById(R.id.img_drr);
    TextView name = (TextView) view.findViewById(R.id.txt_name);
    TextView family = (TextView) view.findViewById(R.id.txt_family);
   // TextView expertise = (TextView) view.findViewById(R.id.expertise);
   // TextView number = (TextView) view.findViewById(R.id.number);
   // TextView address = (TextView) view.findViewById(R.id.address);
   // TextView phone = (TextView) view.findViewById(R.id.phone);


    DrLists drLists = getItem(position);
    name.setText(drLists.getName());
    family.setText(drLists.getFamily());
   // expertise.setText(drLists.getExpertise());
   // number.setText(drLists.getNumber());
   // address.setText(drLists.getAddress());
   // phone.setText(drLists.getPhone());
try {
    Resources res =m_context.getResources();
    int resourceId = res.getIdentifier(drLists.getImg(),"mipmap",m_context.getPackageName());
    img.setImageResource(resourceId);
}catch (Exception e) {}
        return view;
    }
}

我的查询是否正确?

好。现在我的问题是继续这项工作怎么办?  在活动搜索上写什么? 感谢您的有用答案

0 个答案:

没有答案