我无法写入EditText,当我尝试写东西时它会消失,因为当我修改数据时会调用getView()

Yaq*_*mad 5 android listview inline-editing android-softkeyboard android-edittext

编辑:

我发现原因是当我尝试编辑某些内容时调用了getView(),因此加载了DataAdapter中的数据并且我编辑的更改消失了.

编辑:

我观察到一件事,如果列表视图中的行数很少,那么就可以了,但是如果列表视图无法在可见屏幕中显示很多行(滚动条似乎滚动到其他记录),那么问题就出现了!

我正在开发使用ListView实现INLINE EDITING的项目,即可以在listview中编辑数据.

我为ListView的每个项目/行定义了一个xml.我正在使用Custom DataAdapter将数据与ListView绑定.

当我第一次加载ListView加载该活动时,我可以编辑数据,它工作正常.当编辑某些内容时,更改将保存到SQLite数据库中,我有一个用于此目的的按钮.

现在的问题是,在第一次保存数据并再次加载列表视图后,我再也无法编辑数据了.当我尝试编辑数据时,键盘出现然后自动消失,并且ENTERED DATA也会消失.请看屏幕截图.

有人可以帮我解决这个问题吗?

我的自定义适配器类:

public class QuestionAdapter extends ArrayAdapter<QuestionEntity> {
      private ArrayList<QuestionEntity> items;
      private Context CurrentContext;
      private QuestionEntity CurrentItem;
      private Cursor    OptionsCursor;


    public QuestionAdapter(Context context,  ArrayList<QuestionEntity> items, Cursor curOptions) 
    {
        super(context, R.layout.grid_item, items);
        this.CurrentContext = context;
        this.items          = items;
        this.OptionsCursor  = curOptions;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        //verify that the items list is still valid since
        //the list may have been cleared during an update
        if ((items == null) || ((position + 1) > items.size()))
                return convertView; //Can't extract item

        CurrentItem = items.get(position);    

        if(convertView == null) 
        {
            LayoutInflater inflater = LayoutInflater.from(CurrentContext);
            convertView = inflater.inflate(R.layout.grid_item, null);
        }

        if (convertView != null) 
        {

            TextView txtQuestion = (TextView) convertView.findViewById(R.id.txtQuestion);
            txtQuestion.setText(CurrentItem.getTitle());

            Spinner cmbOptions = (Spinner)convertView.findViewById(R.id.cmbOptions);

            /*
             * Load the options from OptionsCursor
             */

            LoadOptions(cmbOptions);

            /*
             * Attach onItemClick event with cmbOptions 
             * When the user change the option we will populate the comments based on the option
             */

            cmbOptions.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) 
            {
                try
                {
                    //If MyCondition is true show msg to user.

                }
                catch(Exception ex)
                {
                    ex.toString();
                }

            }
            });

        }
        return convertView;

    }

    private void LoadOptions(Spinner iacOptions)
    {
        //Load data in the spinner using the OptionsCursor

    }

}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

a.c*_*ch. 1

尝试修改您的代码并查看是否Adapter.getView(..)调用了不应调用的方法。这可能是由于 的冗余调用而发生的notifyDataSetChanged()

只需向这些方法添加日志记录,看看它们是否在正确的地点和时间被调用。