0

我在 ListView 中有带有 EditText 和 TextView 的自定义行。显示第一个 TextView,当用户点击 TextView 时,它应该转换为 Edittext。我试过这个

listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View myView,
                int index, long mylng) {

            TextView lastTextBox;
                EditText lastEditBox;



            for (int count = 0; count < adapter.getCount(); count++) {

                lastEditBox = (EditText) listView.getChildAt(
                        count).findViewById(R.id.NameEditTxt);
                lastTextBox = (TextView) listView.getChildAt(
                        count).findViewById(R.id.NameTxt);

                if (count != index) {

                    lastTextBox.setVisibility(View.VISIBLE);

                    lastEditBox.setVisibility(View.GONE);

                    if (isChanged
                            && !(lastEditBox.getText().toString()
                                    .equalsIgnoreCase(""))) {
                        String modifiedData = lastEditBox.getText()
                                .toString();

                        dataModel = arrayList.get(index);

                        dataModel.setName(modifiedData);

                        lastTextBox.setText(dataModel.getName());

                        dNames[prevIndex]=dataModel.getName();                      
                        System.out.println("01-----------"+prevIndex);
                        isChanged = false;

                    }
                } else {
                    String data;
                    lastEditBox.setVisibility(View.VISIBLE);
                    lastTextBox.setVisibility(View.GONE);
                    data = lastTextBox.getText().toString();
                    lastEditBox.setText(data);
                    isChanged = true;
                }

                lastEditBox.setOnKeyListener(new OnKeyListener() {
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        // If the event is a key-down event on the "enter" button
                        if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                            (keyCode == KeyEvent.KEYCODE_ENTER)) {                              

                            hideSoftKeyboard(lastEditBox);

                          return true;
                        }
                        return false;
                    }

                }); 
            }
            prevIndex = index;

            System.out.println("02-----------"+prevIndex);
        }

    });

我想替换用户在 TextView 中输入的数据,我无法获取上一行索引。任何想法来解决这个问题?

4

0 回答 0