public class UsersAdapter extends BaseAdapter {
public class UsersAdapter extends BaseAdapter {
private static LayoutInflater inflater = null;
public List<User> allUsers;
private Context context;
/*************
* Constructor
*****************/
public UsersAdapter(Context ctx, ArrayList<User> data) {
context = ctx;
allUsers = data;
inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return allUsers.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View rowView = convertView;
UserViewHolder holder = new UserViewHolder();
final User user = allUsers.get(position);
if(convertView==null)
{
rowView = inflater.inflate(R.layout.boxer_item, null);
holder.name = (TextView) rowView.findViewById(R.id.txt_name);
holder.icon = (ImageView) rowView.findViewById(R.id.img_user);
rowView.setTag(holder);
}
else
{
holder = (UserViewHolder) rowView.getTag();
}
holder.name.setText(user.getName());
Glide.with(context).load(user.getImage()).into(holder.icon);
rowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Toast.makeText(context, "You Clicked " + user.getName(), Toast.LENGTH_SHORT).show();
if (user.getName().equals("Ramon \nDekkers")) {
Fragment fragment = new Ramon_dekkers();
FragmentManager fragmentManager = context.getFragmentManager(); -> Eso falla
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame,fragment); -> Y aqui
fragmentTransaction.addToBackStack(null); //If you want to add to back stack
fragmentTransaction.commit();
}
}
});
return rowView;
}
private static class UserViewHolder {
public ImageView icon;
public TextView name;
}
}
}