나는 JSON 파일을 가지고 있으며 다음과 같이 보입니다. 나는 단지 1 페이지에서 SMS 로그 (fromSMS 및 toSMS)의 전체 목록을보고 날짜와 시간에 따라 적절하게 정렬하는 안드로이드 애플 리케이션에서 내 관리 사용자에 대한 하나의 단일보기를 만들 수 있는지 궁금 해서요? 지금은 2 개의 다른 레이아웃, 2 개의 다른 자바 클래스를 사용하여 서로 다른 두 개의보기에서 toSMS 및 fromSMS를 보여줍니다 (즉, 관리 사용자는 toSMS 버튼을 클릭하여 모든 toSMS 세부 사항을 볼 수 있고 fromSMS 버튼은 모든 fromSMS 세부 사항을 볼 수 있습니다). 모든 조언이나 조언은 깊이 감사 할 것입니다. 당신이 당신이 개 JSON 배열을 결합 후1 안드로이드의 2 가지 JSONObject 목록보기
{
"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;
}
}
안녕하세요, 저는 이것을 얻지 못하기 때문에 자바 클래스에 새로운 클래스를 만들고 부울을 만드시겠습니까? 이것에 대한 안내서가 있습니까? 나는 여전히 Java에 대해 매우 익숙하지 않다. – iOSAndroid
당신의 어댑터 클래스를 보여 주실 수 있습니까? – Rahul
안녕하세요, 편집 된 게시물의 상단을 참조하십시오. – iOSAndroid