Created
May 11, 2016 13:25
-
-
Save jcroot/c1004e7b8c3d10b1ef982b9968a75c4f to your computer and use it in GitHub Desktop.
MessagesArrayAdapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.arrobasoft.claxoo.adapters; | |
import android.content.Context; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ArrayAdapter; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import com.arrobasoft.claxoo.R; | |
import com.arrobasoft.claxoo.entities.SmsItem; | |
/** | |
* Created by jadams on 07/03/2016. | |
*/ | |
public class MessagesArrayAdapter extends ArrayAdapter<SmsItem> { | |
final static int SMS_RECEIVE = 1; | |
final static int SMS_SENT = 2; | |
public MessagesArrayAdapter(Context context, int resource) { | |
super(context, resource); | |
} | |
@Override | |
public SmsItem getItem(int position) { | |
return super.getItem(super.getCount() - position - 1); | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
View listItemView = convertView; | |
if (null == convertView){ | |
listItemView = inflater.inflate( | |
R.layout.item_sms_item, | |
parent, | |
false | |
); | |
} | |
TextView created_at = (TextView)listItemView.findViewById(R.id.created_at); | |
TextView sms_text = (TextView)listItemView.findViewById(R.id.sms_text); | |
ImageView in_out = (ImageView)listItemView.findViewById(R.id.inout); | |
SmsItem sms = getItem(position); | |
if (sms.getIn_out() == SMS_RECEIVE){ | |
in_out.setImageResource(R.drawable.ic_action_arrow_right); | |
}else if (sms.getIn_out() == SMS_SENT){ | |
in_out.setImageResource(R.drawable.ic_action_arrow_left); | |
}else{ | |
in_out.setImageResource(R.drawable.ic_action_emo_shame); | |
} | |
created_at.setText(sms.getCreated_at()); | |
sms_text.setText(sms.getMessage()); | |
return listItemView; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment