2016-08-18 5 views
0

私はJSONファイルを持っており、このような感じです。私はそれが1つのページだけでsmsログ(fromSMSとtoSMS)の完全なリストを表示し、それに応じて日時に整理するためにアンドロイドアプリで私の管理ユーザーのための1つの単一のビューを作成することが可能かどうかのだろうか?今のところ2つの異なるレイアウト、2つの異なるJavaクラスを使用してtoSMSとfromSMSを2つの異なるビューに表示しています(つまり、adminユーザーはtoSMSボタンをクリックしてfromSMS詳細を表示し、fromSMSボタンを押すとすべてfromSMS詳細を表示)。どんな指導や助言も深く感謝します。1 Androidリストビュー2種類のJSONObjects

{ 
    "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; 
    } 
} 

答えて

0

、 1は、いくつかのフラグに

Class SmsModel{ 
     String smsid; 
     String from_user; 
     String to_user; 
     String Message; 
     String date_time; 
     String created_at; 
     String updated_at; 
     boolean fromSms; //true for fromSMS and false for toSMS 
} 

を使用して新しいモデルを作成し、あなたはすでにちょうどArrayListの でそれを修正し、アダプタに設定のArrayListを持っています。

と@Override パブリックビューgetViewメソッド(INT位置、表示convertView、のViewGroup親) {ビュー行

アダプタ内部。 行= 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()); 
    if(smsHistory.getFromSms){ 
     // - fromSms 
    } else { 
     // - toSms 
    } 
    return row; 
} 
+0

こんにちは、私はこれを取得していないので、Javaクラスで新しいクラスを作成してブール値を作成しますか?これについてのガイドがありますか?私はまだJavaに全く新しいです – iOSAndroid

+0

あなたのアダプタクラスを教えてください。 – Rahul

+0

こんにちは、上の編集されたポストを参照してください。 – iOSAndroid

関連する問題