Skip to content

Instantly share code, notes, and snippets.

@JaydipZala
Created September 26, 2016 06:47
Show Gist options
  • Save JaydipZala/016909597db21626b24f63073f8d2674 to your computer and use it in GitHub Desktop.
Save JaydipZala/016909597db21626b24f63073f8d2674 to your computer and use it in GitHub Desktop.
Adapters
public class CommentAdapter extends BaseAdapter {
private ArrayList<Comment> arrComments;
private Context mContext;
SharedPreferences mPrefs;
public CommentAdapter(Context mContext, ArrayList<Comment> arrComments) {
this.mContext = mContext;
this.arrComments = arrComments;
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(this.mContext);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return arrComments.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Comment mComment = arrComments.get(position);
View rowView;
if (mComment.user_id.equals(mPrefs.getString(General.PREFS_USER_Id, ""))) {
rowView = inflater.inflate(R.layout.list_item_send_msg, parent,
false);
Utils.setFont((ViewGroup) rowView, Utils.getFontRegular(mContext));
} else {
rowView = inflater.inflate(R.layout.list_item_receive_msg, parent,
false);
Utils.setFont((ViewGroup) rowView, Utils.getFontRegular(mContext));
}
TextView txtMsg = (TextView) rowView.findViewById(R.id.txtMsg);
TextView txtDateAndTime = (TextView) rowView
.findViewById(R.id.txtDateAndTime);
txtMsg.setText(mComment.comment);
txtDateAndTime.setText(Utils.am_pm_of_date(mComment.created_date));
return rowView;
}
}
public class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment