BaluEdo
BaluEdo

Reputation: 119

Android CursorAdapter with EditText problem

In my Appliaction I use a CursorAdapter. This displays a list, which is part of a RelativeLayout. This List includes several elements(TextView, Button, EditText). The EditText does not normally appear on the screen.The problem: I import any data to a EditText and scroll the screen. In this moment I see the imported data in another EditText. OR:

Another case. There are 3 EditText. I use the virtual Keyboard (For example use the second editText). I get in the data to the Edit Text. Push the Back Button. And the data goes to the Edit Text below. (So the data go to the third Edit Text) Here is the CursorAdapter Code:

class OOSListadapter extends CursorAdapter{
        OOSListadapter(Cursor c){
            super(OOS.this,c);
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            OOSRow newRow = (OOSRow)view.getTag();
            newRow.populateRow(cursor);
        }

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            LayoutInflater inflater=getLayoutInflater();
            View row=inflater.inflate(R.layout.oos_row, parent, false);
            OOSRow newRow = new OOSRow(row);

            row.setTag(newRow);

            return (row);
        }
    }

And here is one row from my application list.

class OOSRow {
        private TextView row_Action = null;;
        private TextView row_Must = null;;
        private TextView row_Lack = null;;
        private TextView row_itemName = null;;
        private EditText row_price = null;;
        private Button row_detail = null;
        private View row = null;

        OOSRow (View row){
            this.row = row;

            row_Action = (TextView)row.findViewById(R.id.oos_row_SignalA);
            row_Must = (TextView)row.findViewById(R.id.oos_row_SignalK);
            row_Lack = (TextView)row.findViewById(R.id.oos_row_SignalO);
            row_itemName = (TextView)row.findViewById(R.id.oos_row_itemLabel);
            row_price = (EditText)row.findViewById(R.id.oos_row_EditText);
            row_detail = (Button)row.findViewById(R.id.oos_row_detailButton);
        }

        void populateRow (Cursor c){
            Cursor specCursor = dbLoc.Query("SELECT PRICE, LACK, ORDERED FROM ORDERED WHERE ITEMID='"+ c.getString(1) +"'", null);
            specCursor.moveToFirst();
            row_itemName.setText(c.getString(2));
            row_itemName.setContentDescription(c.getString(1));
            if (specCursor.getString(1).toString().equals("Y")){
                row_itemName.setBackgroundColor(Color.parseColor("#FF0000"));
                row_itemName.setTextColor(Color.parseColor("#FFFFFF")); 
            }else{
                row_itemName.setBackgroundColor(Color.parseColor("#000000"));
                row_itemName.setTextColor(Color.parseColor("#FFFFFF"));
            }   
            row_itemName.setOnClickListener(SelectedLackItem);

            if (c.getString(5).toString().equals("I")){
                row_Action.setTextColor(Color.parseColor("#000000"));
                row_Action.setBackgroundColor(Color.parseColor("#FF0000"));
            }
            else{
                row_Action.setTextColor(Color.parseColor("#FFFFFF"));
                row_Action.setBackgroundColor(Color.parseColor("#000000"));
            }
            if (c.getString(4).toString().equals("I")){
                row_Must.setTextColor(Color.parseColor("#000000"));
                row_Must.setBackgroundColor(Color.parseColor("#00FF00"));
            }
            else{
                row_Must.setTextColor(Color.parseColor("#FFFFFF"));
                row_Must.setBackgroundColor(Color.parseColor("#000000"));
            }

            specCursor = dbLoc.Query("SELECT LACK FROM LASTORDERED WHERE ITEMID='"+c.getString(1)+"' AND COMPANYID ='"+dbLoc.GetCompanyId()+"'", null);
            if (specCursor.moveToFirst())
            {
                if (specCursor.getString(0).toString().equals("I")){
                    row_Lack.setTextColor(Color.parseColor("#000000"));
                    row_Lack.setBackgroundColor(Color.parseColor("#0000FF"));
                }else{
                    row_Lack.setTextColor(Color.parseColor("#FFFFFF"));
                    row_Lack.setBackgroundColor(Color.parseColor("#000000"));
                }
            }

            row_detail.setOnClickListener(OpenDetailScreenButton);
            row_detail.setContentDescription(c.getString(1));
            row_price.setContentDescription(c.getString(1));
            row_price.setInputType(0);
            /*row_price.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    row_price.setInputType(InputType.TYPE_CLASS_NUMBER);
                }

                @Override
                public void afterTextChanged(Editable s) {
                }
            });*/

            specCursor.close();
            specCursor = null;
        }
    }

And some pictures:

When I get in any input After Back Button: Change the EditText Text

Any Idea?

Upvotes: 0

Views: 1591

Answers (1)

artkoenig
artkoenig

Reputation: 7257

I had a very similar problem. The following solution helped me:

<activity android:name= ".yourActivity" android:windowSoftInputMode="adjustPan"/>

Upvotes: 2

Related Questions