I am a new Android Programming.Please take my hand! I have a big custom listview that The database is filled. I have two Textview and one Imageview in custom listview. this is my Model class for getting and setting:
private int id;
private String name;
private String family;
private String img;
my database class includes four value:
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";
I would search to Items of big listview in Other Activity. this is my query in database class:
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;
}
This is my Adapter class:
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;
}
}
Is my query correctly?
Well. now my problem is Continuing this work what to do? What to write on Activity Search? Thank you for your helpful answers