java - 数组中 TextEdit 中的参数不正确

标签 java android arrays xml android-edittext

抱歉我的英语不好。我用谷歌翻译。 我只是为安卓编写了一个游戏。 对于我的问题,我在数组中进行游戏内检查。 在这种情况下,它是显示的支票的值(value)。 然后支票的金额会显示在文本编辑中并支付按钮。 当按下按钮时,将在文本编辑期间支付输入的值。 但是,只有支付的全部费用,没有部分金额。 我的问题是没有交给编辑后的文本。 只是从头开始显示传递的值。 为什么?我的错误在哪里? 我用一些??标记了字符区域。

 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);
                }
            }

最佳答案

您实例化了 EditText 两次,这就是您设置的值丢失的原因 -

                    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 - 数组中 TextEdit 中的参数不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36658021/

相关文章:

java - 读取对象输入流时Java中的EOFexception

java - Java 中字符串是如何创建和存储的?

c# - 如何为 x86 android 交叉编译单声道

arrays - 在动态多维数组中搜索、排序、匹配 - VBA

Java 正则表达式不允许字符串特殊字符

java - 将 List<Tuple> 转换为 List<Bean>

java - Android 小部件和持久数据

android - 更新 RecyclerView.Adapter

arrays - 如何复制矩阵中超过阈值的值并将矩阵的其余部分设置为 0?

c++ - 为数组分配空间