Android CursorAdapter 与 EditText 问题

发布于 2024-10-29 07:54:58 字数 5120 浏览 4 评论 0原文

在我的应用程序中,我使用 CursorAdapter。这将显示一个列表,它是RelativeLayout 的一部分。该列表包含多个元素(TextView、Button、EditText)。 EditText 通常不会出现在屏幕上。问题:我将任何数据导入到 EditText 并滚动屏幕。此时我在另一个 EditText 中看到导入的数据。或者:

另一个案例。有3个EditText。我使用虚拟键盘(例如使用第二个editText)。我将数据输入到编辑文本中。按后退按钮。数据将转到下面的编辑文本。 (所以数据转到第三个编辑文本) 这是 CursorAdapter 代码:

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);
        }
    }

这是我的应用程序列表中的一行。

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;
        }
    }

还有一些图片:

当我输入任何内容时 返回按钮后: 更改 EditText 文本

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抚你发端 2024-11-05 07:54:58

我有一个非常相似的问题。以下解决方案帮助了我:

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

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

<activity android:name= ".yourActivity" android:windowSoftInputMode="adjustPan"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文