【问题标题】:Incorrect parameter in TextEdit in the array数组中 TextEdit 中的参数不正确
【发布时间】:2016-04-15 22:46:19
【问题描述】:

对不起,我的英语不好。我使用谷歌翻译。 我只是为android编写了一个游戏。 对于我的问题,我会在数组中进行游戏检查。 在这种情况下,显示的是支票的价值。 然后支票的金额在显示的文本编辑中并支付按钮。 当按下按钮时,在 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);
                }
            }

【问题讨论】:

  • 特别感谢编辑谢尔盖·格洛托夫

标签: java android arrays xml android-edittext


【解决方案1】:

您正在实例化您的 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()); 声明,你就可以开始了!!

【讨论】:

  • 如果我这样做会使应用程序崩溃。 java.lang.IllegalStateException:指定的孩子已经有一个父母。您必须首先在孩子的父母上调用 RemoveView ()。如果我((ViewGroup)setconditions.getParent())。 RemoveView(setconditions) 使用 EditText 不出现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-20
  • 1970-01-01
  • 1970-01-01
  • 2020-03-13
  • 2021-01-11
  • 2023-04-11
相关资源
最近更新 更多