Situation:
I have an android app where users do certain actions and those actions should be shown in a feed like Facebook's feed. Actions are 4 types - become friends with, follow somebody, comment and rate.
What I know how to do (see example below*)
I know how to extend BaseAdapter and customize its getView method so I can create a custom list item that I can later populate a listview with. Example - a list of a user's friends having their avatars, their names and a couple of buttons for each.
What I dont know how to do and Im asking your help with
I dont know how to make the feed show different customized layouts for the last 10 actions that happened - this guy became friends with that guy, then this guy rated that guy's work, then this guy commented on that thing...
How do I implement that?
*An example of creating a custom adapterable item and then populating a list view with a bunch of them:
public class MyProfileFriendAdapter extends BaseAdapter {
private ArrayList<String> userNames = new ArrayList<String>();
private ArrayList<String> userAvatarPaths = new ArrayList<String>();
private ArrayList<Integer> userIds = new ArrayList<Integer>();
private Context context;
private LayoutInflater layoutInflater;
private ImageButton iMyFriendsFriendAvatarImage;
private TextView tvMyFriendsListFriendName;
private Button bMyFriendsMessage;
private Button bMyFriendsUnfriend;
public MyProfileFriendAdapter(Context context, ArrayList<String> userNames, ArrayList<String> userAvatarPaths, ArrayList<Integer> userIds){
this.context = context;
this.userNames = userNames;
this.userAvatarPaths = userAvatarPaths;
this.userIds = userIds;
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return userIds.size();
}
@Override
public Object getItem(int arg0) {
return userIds.get(arg0) ;
}
@Override
public long getItemId(int position) {
return userIds.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null) {
convertView = layoutInflater.inflate(R.layout.item_adapterable_my_profile_friend, parent, false);
}
iMyFriendsFriendAvatarImage = (ImageButton) convertView.findViewById(R.id.iMyFriendsFriendAvatarImage);
tvMyFriendsListFriendName = (TextView) convertView.findViewById(R.id.tvMyFriendsListFriendName);
bMyFriendsMessage = (Button) convertView.findViewById(R.id.bMyFriendsMessage);
bMyFriendsUnfriend = (Button) convertView.findViewById(R.id.bMyFriendsUnfriend);
tvMyFriendsListFriendName.setText(userNames.get(position));
iMyFriendsFriendAvatarImage.setImageBitmap(BitmapFactory.decodeFile(userAvatarPaths.get(position)));
return convertView;
}
}
then in the activity that holds the list view I do as follows:
listOfFriends = (ListView) findViewById(R.id.lvMyProfileFriendsHolder);
MyProfileFriendAdapter myProfileFriendAdapter = new MyProfileFriendAdapter(this, userNames, userAvatarPaths, userIds);
listOfFriends.setAdapter(myProfileFriendAdapter);
So what do I do when I need to use various different adapterable items in the same list, according to the last actions that users did in my app?