Showing next item in array in listview

  • Replies:0
Javier Coronel
  • Forum posts: 2

Nov 27, 2013, 7:40:48 PM via Website

I have just started reading "Android for Dummies", and I am making an application in which you have some customers in an array list. I need to display them in a list view with all their attributes(Name, id, etc). I was wondering how can I display each one of them one at a time when I press a button, instead of having them all in a row.

This is the code so far, as you can see is a simple list view:

Coustomers.java

public class Coustomers {
public String username;
public String id;
public UserRecord(String username, String email) {
this.username = username;
this.id = id;
}

Adapter.java

public class UserItemAdapter extends ArrayAdapter<Coustomers> {
private ArrayList<Coustomers> users;
public UserItemAdapter(Context context, int textViewResourceId, ArrayList<Coustomers> coustomer) {
super(context, textViewResourceId, coustomer);
this.coustomer = coustomer;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.listitem, null);
}

UserRecord user = users.get(position);
if (coustomer != null) {
TextView username = (TextView) v.findViewById(R.id.username);
TextView id = (TextView) v.findViewById(R.id.id);

if (username != null) {
username.setText(user.username);
}

if(id != null) {
id.setText("Id: " + user.id );
}
}
return v;
}

Reply