Hot to show info based on what user profile has in android?

I have a ListView and each row contains a different User object.

A User has these different fields:

  • List of things I like
  • List of things I hate
  • List of games I play
  • Description of myself

Now, when I populate the ListView, I want to show different things that each user has filled out. So for example, one row might show 'things I like' filled out, while another might show the 'description of myself'.

I don't want to adjacent rows to be showing the same type of row. All this code will be inserted into my BaseAdapter's getView methood.

What would be the best logic in terms of pseudocode to achieve this?

// Creates arraylist of elements that are complete in profile
List<String> profileElements = new ArrayList<String>();
if (user.getGameOwned() != null && user.getGameOwned().size() > 2) {
if (user.getAboutMe() != null && !user.getAboutMe().isEmpty()) {
if (user.getIAm() != null && user.getIAm().length > 2) {
if (profileElements.size() > 0) {
    String randomElement = profileElements.get(new Random().nextInt(profileElements.size() - 1));
    if (randomElement.equals(KEY_GAMES_PLAYED)) {
        // do whatever here
    else if (randomElement.equals(KEY_ABOUT_ME)) {
        // do whatever

Last updated:11/19/2014 12:04:28 AM

1 Answers

Anonymous User
Anonymous User

You could try this approach, in your BaseAdapter put a verification if what list do you want to show.

For example:

int ctr = 1; // your counter - try to declare it on the
global level if(ctr<4){//your 4 types of list - 
     display(ctr); //print the current ctr
     ctr = 1; //make the value to 1 for the next batch of loop


display(int index){ 
    switch (index){
        case 1:
             //List of things I like
        case 2:
             //List of things I hate
        case 3:
            //List of games I play
        case 4:
             //Description of myself

You could also do random.nextInt(4) but it might have the same result each row.