2016-05-11 6 views
1

ダイナミックビューを線形レイアウトに拡張していますが、逆に表示されます。私はtooteet.getMeasureJson()のログ値を取得していますダイナミックアイテムをリニアレイアウトに追加すると逆順表示されます。

​​

は、ここで私はaddMeasureViewがあるの内側法の下

private void addMeasureView(final Measure measure, int position) { 
     Log.d("ss","adding measure data value ________________"+measure.value+" position __________"+position); 

     final View parent = getLayoutInflater().inflate(R.layout.view_measure_tooteet_item, mDisplayContainer, false); 

     final TextView txtDescription, txtValues, txtStartDateTime, txtEndDateTime, labelTaxIncluded, labelTaxColon; 
     final ImageView imgEdit, imgDelete; 
     final LinearLayout lnrDescription, lnrStartLayout, lnrEndLayout; 
     final View mViewDivider; 
     txtDescription = (TextView) parent.findViewById(R.id.txt_description); 
     txtValues = (TextView) parent.findViewById(R.id.values); 
     txtStartDateTime = (TextView) parent.findViewById(R.id.start_date_and_time); 
     txtEndDateTime = (TextView) parent.findViewById(R.id.end_date_and_time); 
     mViewDivider = (View) parent.findViewById(R.id.view_divider); 
     imgEdit = (ImageView) parent.findViewById(R.id.edit); 
     imgDelete = (ImageView) parent.findViewById(R.id.delete); 
     lnrDescription = (LinearLayout) parent.findViewById(R.id.lnr_description); 
     lnrStartLayout = (LinearLayout) parent.findViewById(R.id.lnr_start_layout); 
     lnrEndLayout = (LinearLayout) parent.findViewById(R.id.lnr_end_layout); 

     if(tooteet.isOwner(getUserPreference())){ 
      imgDelete.setVisibility(View.VISIBLE); 
      imgEdit.setVisibility(View.VISIBLE); 
     }else{ 
      imgDelete.setVisibility(View.GONE); 
      imgEdit.setVisibility(View.GONE); 
     } 

     if(measure.getValue() > 0) { 
      txtValues.setVisibility(View.VISIBLE); 
      if (measure.getValue() % 1 == 0) { 
       txtValues.setText("" + (int) measure.getValue()+ " "+MeasureTypeSelector.getMeasureTypeById(FeedMeasureDetailsActivity.this, measure.getMeasureTypeId())); 
      } else { 
       txtValues.setText("" + measure.getValue()+ " "+ MeasureTypeSelector 
         .getMeasureTypeById(FeedMeasureDetailsActivity.this, measure.getMeasureTypeId())); 
      } 
     }else{ 
      txtValues.setVisibility(View.GONE); 
     } 

     if(!TextUtils.isEmpty(measure.getDescription())){ 
      lnrDescription.setVisibility(View.VISIBLE); 
      txtDescription.setText(measure.getDescription()); 
     } 
     else{ 
      lnrDescription.setVisibility(View.GONE); 
     } 

     if(!TextUtils.isEmpty(measure.getStartDate())) { 
      lnrStartLayout.setVisibility(View.VISIBLE); 
      txtStartDateTime.setText("" + DateConversion.getDateAndTime(measure.getStartDate(), "MMMM dd, yyyy hh:mm a")); 
     } 
     else{ 
      lnrStartLayout.setVisibility(View.GONE); 
     } 

     if(!TextUtils.isEmpty(measure.getEndDate())) { 
      lnrEndLayout.setVisibility(View.VISIBLE); 
      txtEndDateTime.setText("" + DateConversion.getDateAndTime(measure.getEndDate(), "MMMM dd, yyyy hh:mm a")); 
     }else{ 
      lnrEndLayout.setVisibility(View.GONE); 
     } 
// 
//  if(position < mMeasureList.size()){ 
//   mViewDivider.setVisibility(View.VISIBLE); 
//  }else{ 
//   mViewDivider.setVisibility(View.GONE); 
//  } 

     imgDelete.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       final int pos = (Integer) v.getTag(); 
       AlertDialog.Builder builder = AlertUtils.getBuilder(FeedMeasureDetailsActivity.this); 
       builder.setTitle(R.string.delete); 
       builder.setMessage(R.string.delete_tooteet_measure_tuple); 
       builder.setPositiveButton(R.string.yes_caps, new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialog, int which) { 

         if (!BDevice.isInternetConnected(FeedMeasureDetailsActivity.this)) { 
          AlertUtils.showNetworkAlert(FeedMeasureDetailsActivity.this); 
          return; 
         } 

         final Dialog pd = UiUtils.getSpinnerDialog(FeedMeasureDetailsActivity.this, getString(R.string.loading)); 
         pd.show(); 

         getDairyLineApi().deleteMeasureTooteet(mMeasureList.get(pos).getId(), tooteet.getLaneId(), new ResponseHandler() { 
          @Override 
          public void onSuccess(int statusCode, String content) { 
           dismiss(); 
           AlertDialog.Builder builder = AlertUtils.getBuilder(FeedMeasureDetailsActivity.this); 
           builder.setMessage(R.string.deleted_successfully); 
           builder.setPositiveButton(R.string.ok_caps, new DialogInterface.OnClickListener() { 
            @Override 
            public void onClick(DialogInterface dialog, int which) { 
             mDisplayContainer.removeView(parent); 
             mMeasureList.remove(pos); 
             tooteet.setMeasureJson(Measure.getMeasureDetailJSON(mMeasureList)); 
             mTooteetManager.updateMeasureTooteet(tooteet, tooteet.getId()); 
            } 
           }); 
           builder.create().show(); 
          } 

          @Override 
          public void onFailure(int statusCode, String content) { 
           dismiss(); 
           if (!TextUtils.isEmpty(content)) { 
            AlertUtils.showAlert(FeedMeasureDetailsActivity.this, content); 
           } 
          } 

          private void dismiss() { 
           if (pd != null && !isFinishing()) { 
            pd.dismiss(); 
           } 
          } 
         }); 
        } 
       }); 
       builder.setNegativeButton(R.string.no_caps, null); 
       builder.create().show(); 
      } 
     }); 

     imgEdit.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       final int pos = (Integer) v.getTag(); 
       MeasureTooteetSelector measureTooteetSelector = new MeasureTooteetSelector(); 
       measureTooteetSelector.openMeasureDetailSelector(FeedMeasureDetailsActivity.this, mMeasureList.get(pos), 
         new MeasureTooteetSelector.OnMeasureDetailSelectListener() { 
          @Override 
          public void onMeasureSelect(final Measure measureData) { 
           if (!BDevice.isInternetConnected(FeedMeasureDetailsActivity.this)) { 
            AlertUtils.showNetworkAlert(FeedMeasureDetailsActivity.this); 
            return; 
           } 

           final Dialog pd = UiUtils.getSpinnerDialog(FeedMeasureDetailsActivity.this, getString(R.string.loading)); 
           pd.show(); 


           if (measureData != null) { 
            mMeasureList.set(pos, measureData); 
           } 

           getDairyLineApi().updateMeasureTooteet(mMeasureList.get(pos), new ResponseHandler() { 
            @Override 
            public void onSuccess(int statusCode, String content) { 
             dismiss(); 
             AlertDialog.Builder builder = AlertUtils.getBuilder(FeedMeasureDetailsActivity.this); 
             builder.setMessage(R.string.updated_successfully); 
             builder.setPositiveButton(R.string.ok_caps, new DialogInterface.OnClickListener() { 
              @Override 
              public void onClick(DialogInterface dialog, int which) { 

               if (measureData != null) { 
                mMeasureList.set(pos, measureData); 
                tooteet.setMeasureJson(Measure.getMeasureDetailJSON(mMeasureList)); 
                mTooteetManager.updateMeasureTooteet(tooteet, tooteet.getId()); 
                mActionToSend = ACTION_MEASURE_UPDATE; 
                if (measureData.getValue() % 1 == 0) { 
                 txtValues.setText("" + (int) measureData.getValue()+ " "+MeasureTypeSelector.getMeasureTypeById(FeedMeasureDetailsActivity.this, measureData.getMeasureTypeId())); 
                } else { 
                 txtValues.setText("" + measureData.getValue()+ " "+ MeasureTypeSelector 
                   .getMeasureTypeById(FeedMeasureDetailsActivity.this, measureData.getMeasureTypeId())); 
                } 

                Log.d("TAG", "measureData.getStartDate(): "+measureData.getStartDate()); 
                if(!TextUtils.isEmpty(measureData.getStartDate()) && !measureData.getStartDate().equalsIgnoreCase("-1")) { 
                 lnrStartLayout.setVisibility(View.VISIBLE); 
                 txtStartDateTime.setText("" + DateConversion.getDateAndTimeWithoutGMT(measureData.getStartDate(), "MMMM dd, yyyy hh:mm a")); 
                } 
                else{ 
                 lnrStartLayout.setVisibility(View.GONE); 
                } 

                Log.d("TAG", "measureData.getEndDate(): "+measureData.getEndDate()); 
                if(!TextUtils.isEmpty(measureData.getEndDate())&& !measureData.getStartDate().equalsIgnoreCase("-1")) { 
                 lnrEndLayout.setVisibility(View.VISIBLE); 
                 txtEndDateTime.setText("" + DateConversion.getDateAndTimeWithoutGMT(measureData.getEndDate(), "MMMM dd, yyyy hh:mm a")); 
                }else{ 
                 lnrEndLayout.setVisibility(View.GONE); 
                } 

                if(!TextUtils.isEmpty(measureData.getDescription())){ 
                 lnrDescription.setVisibility(View.VISIBLE); 
                 txtDescription.setText(measureData.getDescription()); 
                } 
                else{ 
                 lnrDescription.setVisibility(View.GONE); 
                } 
               } 

              } 
             }); 
             builder.create().show(); 
            } 

            @Override 
            public void onFailure(int statusCode, String content) { 
             dismiss(); 
             if (!TextUtils.isEmpty(content)) { 
              AlertUtils.showAlert(FeedMeasureDetailsActivity.this, content); 
             } 
            } 

            private void dismiss() { 
             if (pd != null && !isFinishing()) { 
              pd.dismiss(); 
             } 
            } 
           }); 
          } 

          @Override 
          public void onCancel() { 
          } 
         }); 

      } 
     }); 

     imgEdit.setTag(position); 
     imgDelete.setTag(position); 
     addView(parent); 
    } 

私のログを使用して測定ビューを追加している

onCreate -- tooteet.getMeasureJson(): [{"id":"3fb2af41-201d-4aca-9479-42af6cca5947","tooteetId":"3d923a95-d8d8-4478-b336-c995cc77407d","laneId":"00000000-0000-0000-0000-000000000000","value":11111,"text":"","measureTypeId":1,"isTimeSet":false},{"id":"ecab9659-7eb5-417a-8f5e-f769629957ae","tooteetId":"3d923a95-d8d8-4478-b336-c995cc77407d","laneId":"00000000-0000-0000-0000-000000000000","value":22222,"text":"","measureTypeId":1,"isTimeSet":false}] 

です以下:

adding measure data value ________________11111.0 position __________0 
adding measure data value ________________22222.0 position __________1 

しかし、私は、レイアウトで、このにそれを見ています。このため

adding measure data value ________________22222.0 
adding measure data value ________________11111.0 

として私に任意のアイデアを提案してください。

これは

import com.kwypesoft.lanes.create_tooteet.LocalTooteetCreator; 
import com.kwypesoft.lanes.utils.DateConversion; 
import com.kwypesoft.lanes.utils.TextUtils; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import java.io.Serializable; 
import java.util.ArrayList; 

public class Measure implements Serializable{ 

    // "id": "398627f1-9392-4b3f-8741-903fbcbbd3be", 
//   "tooteetId": "ab36f69e-a0c8-4f31-aa8d-9b4038a76d57", 
//   "laneId": "00000000-0000-0000-0000-000000000000", 
//   "startDate": "2016-04-26T08:00:00", 
//   "endDate": "2016-04-27T10:00:00", 
//   "value": 125.6500000000000, 
//   "measureTypeId": 20 
    public String id; 
    public String tooteetId; 
    public String laneId; 
    public String startDate; 
    public String endDate; 
    public String description; 
    public double value; 
    public int measureTypeId; 
    public boolean isTimeSet; 

    public Measure() { 
    } 

    public Measure(JSONArray jsonArray) { 
     try { 
      for(int i =0; i<jsonArray.length(); i++){ 
       JSONObject jsonObject = jsonArray.getJSONObject(i); 
       id = jsonObject.optString("id"); 
       tooteetId = jsonObject.optString("tooteetId"); 
       laneId = jsonObject.optString("laneId"); 
       startDate = jsonObject.optString("startDate"); 
       endDate = jsonObject.optString("endDate"); 
       description = jsonObject.optString("text"); 
       value = jsonObject.optDouble("value"); 
       measureTypeId = jsonObject.optInt("measureTypeId"); 
       isTimeSet = jsonObject.optBoolean("isTimeSet"); 
      } 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
    } 

    public static String getMeasureJSON(ArrayList<LocalTooteetCreator.MeasureData> data) { 

     JSONArray jsonArray = new JSONArray(); 

     for (LocalTooteetCreator.MeasureData items : data) { 
      try { 
       JSONObject jsonObject = new JSONObject(); 
       jsonObject.put("value", items.value); 
       jsonObject.put("text", items.description); 
       jsonObject.put("measureTypeId", items.measureTypeId); 
       if(items.startDate != -1){ 
        jsonObject.put("startDate", DateConversion.getDateWithTFromMilliSeconds(items.startTime, items.startDate)); 
       } 

       if(items.endDate != -1){ 
        jsonObject.put("endDate", DateConversion.getDateWithTFromMilliSeconds(items.endTime, items.endDate)); 
       } 
       jsonObject.put("isTimeSet", items.isTimeSet); 
       jsonArray.put(jsonObject); 

      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 


     } 
     return jsonArray.toString(); 

    } 

    public static String getMeasureDetailJSON(ArrayList<Measure> data) { 

     JSONArray jsonArray = new JSONArray(); 

     for (Measure items : data) { 
      try { 
       JSONObject jsonObject = new JSONObject(); 
       jsonObject.put("id", items.id); 
       jsonObject.put("tooteetId", items.tooteetId); 
       jsonObject.put("laneId", items.laneId); 
       if(!TextUtils.isEmpty(items.startDate) && !items.getStartDate().equalsIgnoreCase("-1")){ 
        jsonObject.put("startDate", items.startDate); 
       } 

       if(!TextUtils.isEmpty(items.endDate) && !items.getStartDate().equalsIgnoreCase("-1")){ 
        jsonObject.put("endDate", items.endDate); 
       } 

       jsonObject.put("text", items.description); 
       jsonObject.put("value", items.value); 
       jsonObject.put("measureTypeId", items.measureTypeId); 
       jsonObject.put("isTimeSet", items.isTimeSet); 
       jsonArray.put(jsonObject); 

      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 


     } 
     return jsonArray.toString(); 

    } 

    public String getId() { 
     return id; 
    } 

    public String getTooteetId() { 
     return tooteetId; 
    } 

    public String getLaneId() { 
     return laneId; 
    } 

    public String getStartDate() { 
     return startDate; 
    } 

    public String getEndDate() { 
     return endDate; 
    } 

    public double getValue() { 
     return value; 
    } 

    public int getMeasureTypeId() { 
     return measureTypeId; 
    } 

    public boolean getIsTimeSet() { 
     return isTimeSet; 
    } 

    public String getDescription() { 
     return description; 
    } 

    public boolean isTimeSet() { 
     return isTimeSet; 
    } 

} 
+0

(int i = jsonArray.length() - 1; i> = 0; i--) –

+0

のコードも投稿してください。 getValue()メソッド –

+0

はい。私はそれを行って、私のビューも正しく表示されますが、値11111を表示している間に表示されます。22222 – Sangeetha

答えて

0

こんにちは、私はaddview方法で間違いを行っているのgetValueのための私が使用している私のモデルクラス()です。私addviewメソッドの前に

mDisplayContainer.addView(view, mDisplayContainer.getChildCount() - 1); 

は今、私は私のために働い

mDisplayContainer.addView(view); 

その変化しています。あなたのコメントのためにあまりにもありがとう

関連する問題