I have a JSON file and it looks something like this. I was wondering if it is possible to create 1 single view for my admin users in the android app to view the full list of sms logs(fromSMS and toSMS) in just 1 page and arrange it accordingly in the date and time? Because for now I am using 2 different layouts, 2 different java classes to show toSMS and fromSMS in two different views(in short the admin user have to click toSMS button to view all toSMS details, fromSMS button to view all fromSMS details). Any guidance or advice will be deeply appreciated.
{
"fromSMS": [
{
"smsid": 46,
"from_user": "User2",
"to_user": "User3",
"message": "What's up!",
"date_time": "2015-12-23T02:12:00.000Z",
"created_at": "2015-12-23T02:13:02.929Z",
"updated_at": "2015-12-23T02:13:02.929Z"
}
],
"toSMS": [
{
"smsid": 39,
"from_user": "User11",
"to_user": "User22",
"message": "Hihi",
"date_time": "2015-12-23T01:31:00.000Z",
"created_at": "2015-12-23T01:31:52.314Z",
"updated_at": "2015-12-23T01:31:52.314Z"
}
]
}
SMSHistoryAdapter.Java
public class SMSHistoryAdapter extends ArrayAdapter
{
List list = new ArrayList();
public SMSHistoryAdapter(Context context, int resource)
{
super(context,resource);
}
public void add(SMSHistory object)
{
super.add(object);
list.add(object);
}
@Override
public int getCount()
{
return list.size();
}
@Override
public Object getItem(int position)
{
return list.get(getCount() - position - 1);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row;
row = convertView;
SMSHistoryHolder smsHistoryHolder;
if(row == null)
{
LayoutInflater layoutInflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(R.layout.sms_history_rowlayout,parent,false);
smsHistoryHolder = new SMSHistoryHolder();
smsHistoryHolder.tAccount = (TextView)row.findViewById(R.id.tAccount);
smsHistoryHolder.tMessage = (TextView)row.findViewById(R.id.tMessage);
smsHistoryHolder.tDateTime = (TextView)row.findViewById(R.id.tDateTime);
row.setTag(smsHistoryHolder);
}
else
{
smsHistoryHolder = (SMSHistoryHolder)row.getTag();
}
SMSHistory smsHistory = (SMSHistory)this.getItem(position);
smsHistoryHolder.tAccount.setText(smsHistory.gettAccount());
smsHistoryHolder.tMessage.setText(smsHistory.gettMessage());
smsHistoryHolder.tDateTime.setText(smsHistory.gettDateTime());
return row;
}
static class SMSHistoryHolder
{
TextView tAccount,tMessage,tDateTime;
}
}