如何实现与edittexts定制的ListView监听文字的变化? [英] How to implement listener text changes in custom ListView with edittexts?

查看:190
本文介绍了如何实现与edittexts定制的ListView监听文字的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试保存在ListView EDITTEXT的价值和它的作品,但是当有一个ListView过大,当林编辑1 EditText上,如果我滚动列表视图,另一个是的EditText在同一时间编辑...我不知道该怎么办,我浪费6小时,并没有什么。如果有些能帮助我,请。

im trying to save the values of Edittext in the ListView and it works, but when there is a ListView too large, when Im editing 1 edittext, if I scroll the listview, another EditText is editing at the same time... I don't know what to do, I wasted 6hours, and got nothing. If some can help me, please.

这是自定义列表视图

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final int position2 = position;
        View v = convertView;
        final ViewHolder holder;

        if(v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.lista_item_prepedido, null);

            holder = new ViewHolder();

            holder.codi = (TextView) v.findViewById(R.id.NomProducte);
            holder.nom = (EditText) v.findViewById(R.id.Preu);
            holder.eliminar = (ImageButton) v.findViewById(R.id.delete);
            View eliminarPrepedido = (ImageButton) v.findViewById(R.id.delete);

            if(blocClients.equals("0"))
            {
                eliminarPrepedido.setVisibility(View.GONE);
                holder.nom.setFocusable(false);
            }


            v.setTag(holder);

            holder.nom.setText(items.get(position).getNom());
            holder.nom.addTextChangedListener(new TextWatcher(){

                @Override
                public void afterTextChanged(Editable s) {


                }

                @Override
                public void beforeTextChanged(CharSequence s, int start,
                        int count, int after) {
                    // TODO Auto-generated method stub

                }

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



                    items.get(position2).Nom = s.toString();



                    String preu = items.get(position2).Nom;
                    String nomproducte = items.get(position2).Codic;
                    int position = position2;

                    //mostrarMensaje("Valor: "+preu+"  Nom Producte: "+nomproducte+"  CodiClient: " +CodicClient+ " posicio: "+position);
                    baseDatos = openOrCreateDatabase(nombreBD, MODE_WORLD_WRITEABLE, null);

                    String sqlStr = "UPDATE estadistiques SET ultimpreu = '" +preu+"' WHERE codic_client='"+CodicClient+"' AND desc_article = '"+nomproducte+"' ";
                    baseDatos.execSQL(sqlStr);

                    try {
                        fnGlobal.CreaSincroFitxer(sqlStr);
                    } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    baseDatos.close();
                }


            });


        } else {
            holder = (ViewHolder) v.getTag();

        }


        holder.codi.setText(items.get(position).getCodic());


        holder.eliminar.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

                final int position = position2;
                String CodicClient = null;
                Bundle extras = getIntent().getExtras();
                CodicClient = extras.getString("codiClientTab");
                String nomproducte = items.get(position).Codic;
                int Opcio = 1;


                baseDatos = openOrCreateDatabase(nombreBD, MODE_WORLD_WRITEABLE, null);
                String sqlStr = "DELETE FROM estadistiques WHERE codic_client ='"+CodicClient+"' AND desc_article ='"+nomproducte+"'" ;
                baseDatos.execSQL(sqlStr);

                try {
                    fnGlobal.CreaSincroFitxer(sqlStr);
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                baseDatos.close();

                notifyDataSetChanged();

                onResume();

            }

        });





        return v;
    }
}

有关列表视图的自定义XML项目

Custom XML item for listview

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:background="@drawable/rounded_rectangle"
    android:orientation="horizontal"
    android:padding="6dip" >

    <ImageButton
        android:id="@+id/delete"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="15dp"
        android:background="@drawable/delete" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <EditText
            android:id="@+id/Preu"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/NomProducte"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="5dp"
            android:background="@color/white"
            android:ellipsize="end"
            android:gravity="right"
            android:inputType="numberDecimal"
            android:singleLine="true"
            android:text="nom"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/NomProducte"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/Preu"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="5dp"
            android:layout_weight="0.16"
            android:clickable="false"
            android:ellipsize="end"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:singleLine="true"
            android:text="codi"
            android:textColor="#000000"
            android:textSize="18sp" />

    </RelativeLayout>

</LinearLayout>

非常感谢! :)

Thanks a lot! :)

推荐答案

如果我明白你的问题,这将是很难让这个总是以一种简单的方式来理解的行为。我建议你​​改变你实现这在显示这两个资料片在ListView 2 TextViews的方式。当编辑一个窃听,弹出一个对话框来编辑信息,用户必须再接受或前移到取消列表视图,清楚是怎么回事。综上所述,笔者建议:

If I've understood your problem, it would be very hard to make this always behave in an easy way to understand. I would suggest that you change the way you implement this to have two TextViews in the ListView showing the two piece of information. When the editable one is tapped, bring up a Dialog to edit the information, which the user must then either accept or cancel before the move the listview, making it clear what is going on. In summary, I suggest:


  • NomProducte成为其设置为现在一个TextView。

  • NomProducte的捕捉到onTouch弹出一个对话框显示图像,preU文本TextView的和NomProducte文本作为一个EditText。

  • 用户输入数据到一个。

  • 确定 - >接受新的文本动作

  • 取消 - >忽略新文本动作

这篇关于如何实现与edittexts定制的ListView监听文字的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆