我不能写进去的EditText,它消失当我尝试写一些东西,因为它的getView()被调用,当我修改数据当我、它的、东西、数据

2023-09-06 15:12:18 作者:- 愿为酒花死

编辑:

我发现这就是getView(),当我尝试叫的原因   编辑的东西,所以从DataAdapter的加载数据&安培;我的编辑   变化消失。

I found the reason which is that the getView() is called when i try to edit something, so the data from the DataAdapter is loaded & my edited changes disappears.

编辑:

我观察到的一件事,如果有几排在列表视图则其   OK,但如果有很多行该列表视图不能在显示   可视屏幕(出现滚动条滚动到其他记录),然后   这个问题出现!

i observed one thing, if there are few rows in the listview then its OK, but if there are many rows which the listview can not show in the visible screen (Scroll bar appears to scroll to other records), then the issue arises!!

我的工作,我们已实施INLINE编辑使用的ListView ,即数据可以在列表视图里进行编辑。

I am working on project where we have implemented an INLINE EDITING using ListView, i.e. the data can be edited inside the listview.

我有一个定义的XML为ListView中的每个项目/行。我使用自定义的DataAdapter的数据ListView控件绑定。

I have a defined an xml for each item/row of that ListView. I am using Custom DataAdapter to bind the data with ListView.

当我第一次加载的ListView加载该活动,我可以编辑数据和放大器;它工作正常。当一些编辑保存到SQLite数据库的变化,我有此目的的按钮。

When i first time load that activity the ListView is loaded, i can edit the data & it works fine. When something is edited the changes are saved to the SQLite database, i have a button for this purpose.

现在的问题是,数据被保存后的第一次和放大器;列表视图再次加载,我不能再编辑数据。当我尝试编辑键盘出现和放大器的数据;然后自动与放消失;输入的数据也消失了。请参阅屏幕截图。

Now the issue is that after the data is saved FOR THE VERY FIRST TIME & the listview is loaded again, i can not edit the data anymore. When i try to edit the data the keyboard appears & then disappears automatically & the ENTERED DATA also disappears. Please see the screen shots.

能有一个人帮我解决这个问题?

我的自定义适配器类:

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

    }

}

推荐答案

尝试修改你的code,看看 Adapter.getView(..) 方法被调用时,它不应该。这可能发生,因为 notifyDataSetChanged()

Try to revise your code and see if Adapter.getView(..) method is called when it shouldn't. This could happen because of redundant call of notifyDataSetChanged().

只需添加记录这些方法,看看他们被称为在正确的地点和时间。

Just add logging to these methods and see if they are called at the right place and time.