1

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

Reza
  • 31
  • 9
  • We'll need to see you implementation of your list adapter. Basically you have to set the data of the adapter to the result of findproducts and call adapter.notifyDatasetchanged(). – Jörn Buitink Dec 15 '15 at 07:04
  • Partly realized. Adapter class is now set to edit my question – Reza Dec 15 '15 at 07:08
  • Okay. Now what is your question? If the user commits the search, you obtain your search result list by calling DrList.findProduct, then you clear the adapter (MyListAdapter.clear()), add the list items (MyListAdapter.addAll(Drlist) and notifyDatasetChanged(MyListAdapter.notifyDatasetChanged()). – Jörn Buitink Dec 15 '15 at 07:25
  • [http://stackoverflow.com/questions/14118309/how-to-use-search-functionality-in-custom-list-view-in-android] check this link and do not query from database again when searching – Vivek Mishra Dec 15 '15 at 07:32
  • Thank you.Is it possible to write codes More details in the answer.Thanks – Reza Dec 15 '15 at 07:35

0 Answers0