I can't write into the EditText, it disappears

2019-02-17 11:38发布

EDIT:

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.

EDIT:

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!!

I am working on project where we have implemented an INLINE EDITING using ListView, i.e. the data can be edited inside the 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.

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.

Can some one help me to resolve this issue?

my Custom Adapter class:

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

    }

}

enter image description here

1条回答
一纸荒年 Trace。
2楼-- · 2019-02-17 12:30

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.

查看更多
登录 后发表回答