2016-04-15 45 views
1

對不起我的英文不好。我使用谷歌翻譯。 我只是編程一個android遊戲。 與我的問題我給在遊戲中檢查數組。 在這種情況下顯示的檢查值。 然後檢查的金額顯示在textedit中,並支付一個按鈕。 當按下按鈕時,在文本輸入期間分配輸入的值。 但是,只支付全部費用並且沒有部分金額。 我的問題是沒有交給編輯的文本。 它只是傳遞的值從一開始就顯示。 爲什麼?我的錯誤在哪裏? 我用幾個??標記了字符區域。數組中的TextEdit中的參數不正確

for (int i = 0; i < jArray.length(); i++) { 

        JSONObject jObject = jArray.getJSONObject(i); 
        if(jObject.has("error")){ 
         no_schecks.setVisibility(View.VISIBLE); 
        }else { 
         no_schecks.setVisibility(View.INVISIBLE); 
         final int scheckid = jObject.getInt("scheckid"); 
         final String condition = jObject.getString("condition"); 

        scheckx = new Scheck(condition, scheckid); 

        ll = (TableLayout) rootview.findViewById(R.id.displayLinear); 
        TableRow row = new TableRow(getActivity()); 
        scheckLocalStore.storeScheckData(scheckx); 

        LayoutInflater inflater = getLayoutInflater(getArguments()); 
        View theInflatedView = inflater.inflate(R.layout.activity_scheckx, 
          null); 

        TextView conditions = (TextView) theInflatedView.findViewById(R.id.condition); 
        conditions.setText(" " + scheckx.condition + " ₢ "); 
        conditions = new TextView(getActivity()); 
        row.addView(conditions); 


Log.i("info", "start?????????????????????????????"); 

        EditText setconditions = (EditText) theInflatedView.findViewById(R.id.setcondition); 
        setconditions.setText(scheckx.condition); 
        setconditions = new EditText(getActivity()); 
        row.addView(setconditions); 

Log.i("info", "end?????????????????????????????"); 


        Button btnSetCondition = (Button) theInflatedView.findViewById(R.id.btnSetCondition); 
         final String thisCondition = scheckx.condition; 
         final String thisId = Integer.toString(scheckx.scheckid); 
         final int thatId = scheckx.scheckid; 


Log.i("info", "start?????????????????????????????"); 

         //final String thatCondition = setconditions.getText().toString(); 
         final String thatCondition = ((EditText) theInflatedView.findViewById(R.id.setcondition)).getText().toString(); 

Log.i("info", "end?????????????????????????????"); 


        scheckLocalStore = new ScheckLocalStore(super.getActivity()); 
        btnSetCondition.setId(btnSetCondition.getId()); 
        btnSetCondition.setOnClickListener(new View.OnClickListener() { 
         @Override 
         public void onClick(View v) { 
          switch (v.getId()) { 
           case R.id.btnSetCondition: 

            Log.i("info", "SCHECKKRAM " + thatCondition + " " + thisCondition); 
            Scheck scheck = new Scheck(uid, usersecu, thatId, thisCondition); 
            executeScheck(scheck, thatCondition, thisId); 
            //objFragment = new activity_bank_main(); 
            break; 
          } 
          if(objFragment != null){ 
           FragmentManager fragmentManager = getFragmentManager(); 
           fragmentManager.beginTransaction() 
             .replace(R.id.container, objFragment) 
             .commit(); 
          } 
         } 
        }); 
        //row.setLayoutParams(TableRow.LayoutParams.MATCH_PARENT); 
        row.setGravity(Gravity.CENTER_HORIZONTAL); 
        row.addView(theInflatedView); 
        ll.addView(row, i); 
       } 
      } 
+0

特別感謝編輯sergey glotov –

回答

0

你實例化你的EditText上2倍,這就是爲什麼你設置的值丟失 -

    EditText setconditions = (EditText) theInflatedView.findViewById(R.id.setcondition); // 1st time 
        setconditions.setText(scheckx.condition); 
        setconditions = new EditText(getActivity()); // 2nd time 
        row.addView(setconditions); 

刪除setconditions = new EditText(getActivity());聲明,你是好去!

+0

如果我這樣做會崩潰的應用程序。 java.lang.IllegalStateException:指定的子項已經有父項。您必須先調用子對象的父對象的RemoveView()。 if I((ViewGroup)setconditions.getParent())。 RemoveView(setconditions)使用EditText不會出現。 –