i have created custom view need to display the user detail from the database if the user is have the name staring from some name,all the names should display but when i am doing it displaying the last user detail multiple time for example if i have user details of type name jaya monika,jaya moni like that,it display the jaya moni two times rather than two different names here i am posting my sqlite query
Cursor c= mydatabase.query(true, TABLENAME_1, new String[] { KEY_Name,
KEY_CellPhoneNumber,KEY_CompanyName,KEY_Email_id }, KEY_Name + " LIKE ?",
new String[] {"%"+ name+ "%" }, null, null, null,
null);
and in AsyncTaski am retrieving the userdetail and adding them to userdetail modelcall like
DataHelper databasehelper = new DataHelper(Search.this);
databasehelper.open();
Cursor c= databasehelper.getAllCustomerDetailsByName(_name);
int nam = c.getColumnIndex(KEY_Name);
int cellnumber = c.getColumnIndex(KEY_CellPhoneNumber);
int company = c.getColumnIndex(KEY_CompanyName);
int emailid = c.getColumnIndex(KEY_Email_id);
CustomerSearchModel searchmodel = new CustomerSearchModel();
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
{
flag_data = true;
searchmodel.setName(c.getString(nam));
searchmodel.setCellphone(c.getString(cellnumber));
searchmodel.setCompany(c.getString(company));
searchmodel.setEmailid(c.getString(emailid));
Log.i("Search", searchmodel.getName());
Log.i("Search", searchmodel.getCellphone());
Log.i("Search", searchmodel.getCompany());
Log.i("Search", searchmodel.getEmailid());
customerSearch.add(searchmodel);
}
c.close();
databasehelper.close();
return customerSearch;
and in on create am setting adapter class as like this
searchAdapter = new CustomerSearchAdapter(Search.this, customerSearch);
and my customer adapter class is
public class CustomerSearchAdapter extends BaseAdapter {
private ArrayList<CustomerSearchModel> customerSearchData;
private LayoutInflater layoutInflater;
private Context _context;
public CustomerSearchAdapter(Context context,
ArrayList<CustomerSearchModel> listData) {
this.customerSearchData = listData;
_context = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return customerSearchData.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return customerSearchData.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
if (layoutInflater == null)
layoutInflater = (LayoutInflater) _context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.custom_user_details,
null);
holder = new ViewHolder();
holder.customer_user_name = (TextView) convertView
.findViewById(R.id.user_name);
holder.customer_company_name = (TextView) convertView
.findViewById(R.id.company_name);
holder.customer_phone_number = (TextView) convertView
.findViewById(R.id.phone_number);
holder.customer_emailid_number = (TextView) convertView
.findViewById(R.id.emailid_number);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final CustomerSearchModel customDetailItem = (CustomerSearchModel) customerSearchData
.get(position);
holder.customer_user_name.setText(customDetailItem.getName());
holder.customer_company_name.setText(customDetailItem.getCompany());
holder.customer_phone_number.setText(customDetailItem.getCellphone());
holder.customer_emailid_number.setText(customDetailItem.getEmailid());
return convertView;
}
static class ViewHolder {
TextView customer_user_name;
TextView customer_company_name;
TextView customer_phone_number;
TextView customer_emailid_number;
}
}
please help me to solve this problem i have strucked in this problem advance thanks for giving or suggesting me solution for this problem
Aucun commentaire:
Enregistrer un commentaire