Reputation: 51
hello im having trouble putting data in listview i created the resource file for it and i made the custom array adapter for it but when i run the app it shuts down
here is the custom adapter class
public class MembreAdapter extends BaseAdapter{
private Context context;
private List<Membre> memb;
public MembreAdapter(Context context, List<Membre> memb) {
this.context = context;
this.memb = memb;
}
@Override
public int getCount() {
return memb.size();
}
@Override
public Object getItem(int position) {
return memb.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v= View.inflate(context,R.layout.display_member_row,null);
TextView tnom = (TextView)v.findViewById(R.id.nom_id);
TextView tprenom = (TextView)v.findViewById(R.id.prenom_id);
TextView temail = (TextView)v.findViewById(R.id.email_id);
TextView tnumero= (TextView)v.findViewById(R.id.numero_tele_id);
tnom.setText(memb.get(position).getNom());
tprenom.setText(memb.get(position).getPrenom());
temail.setText(memb.get(position).getEmail());
tnumero.setText(memb.get(position).getNumero());// thats the line that sstack trace points at
return v;
}
}
and the class that i want to show the data in
BaseDeDonee bdd = new BaseDeDonee(this);//database
mem=new ArrayList<>();
Cursor c =bdd.GETallMem();
//function returns all the data from table person
c.moveToFirst();
while(c.moveToNext()){
nom= c.getString(c.getColumnIndex("nom"));
prenom=c.getString(c.getColumnIndex("prenom"));
email=c.getString(c.getColumnIndex("profile"));
numero=c.getInt(c.getColumnIndex("numero_tel"));
mem.add(new Membre(nom,prenom,email,numero));
}
listView=(ListView)findViewById(R.id.listView);
mema= new MembreAdapter(getApplicationContext(),mem);
listView.setAdapter(mema);
listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),"it works " ,Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
thanks for the help in advance
Upvotes: 0
Views: 44
Reputation: 7543
You need to pass a String to the setText method. Try this -
tnumero.setText(Integer.toString(memb.get(position).getNumero()));
Upvotes: 1
Reputation: 465
I think you are giving an integer to the setText method which makes it try to find an string resource with an id equal to that integer , that causes a resource not found exception.
try changing it to
tnumero.setText(""+memb.get(position).getNumero());
Upvotes: 1