Listview有edittext

时间:2014-02-12 07:16:18

标签: android listview baseadapter

我有一个带有一些edittexts的分段Listview。如果我第一次点击该edittext,软键盘工作正常。如果我隐藏键盘并单击另一个编辑文本键盘出现但刷新几次。此时我也无法在该ediitext上写任何内容。有人请帮忙

这是我的适配器类

public class ListAdapter_baradmin extends BaseAdapter{

    Context ctx;
    LayoutInflater lInflater;
    public ArrayList myItems = new ArrayList();


    public static String[] str_Id = new String[datalength];
    public static String[] str_Idoriginal = new String[datalength];
    public static String[] str_Desc = new String[datalength];
    public static String[] str_UOM = new String[datalength];
    public static String[] str_Parlevel = new String[datalength];
    public static String[] str_Openingstock = new String[datalength];
    public static String[] str_Reg = new String[datalength];
    public static String[] str_Intertransfer = new String[datalength];
    public static String[] str_Closingstock = new String[datalength];
    public static String[] str_Remark = new String[datalength];

    SeparatedListAdapter separatedListAdapter;

    ArrayList<String> Data_id           = new ArrayList<String>();
    ArrayList<String> Data_name         = new ArrayList<String>();
    ArrayList<String> Data_parlevel     = new ArrayList<String>();
    ArrayList<String> Data_uom          = new ArrayList<String>();


    public ListAdapter_baradmin(Context context
            ,ArrayList<String> Items_id
            ,ArrayList<String> Items_desc
            ,ArrayList<String> Items_perunitcost
            ,ArrayList<String> Items_uom
            ,ArrayList<String> Items_idoriginal) {

        ctx = context;   

        Data_id         .addAll(Items_id);
        Data_name       .addAll(Items_desc);
        Data_parlevel   .addAll(Items_perunitcost);
        Data_uom        .addAll(Items_uom);


        for(int i=0;i<Items_id.size();i++){

            str_Id[i]           = Items_id.get(i);
            str_Idoriginal[i]   = Items_idoriginal.get(i);
            str_Desc[i]         = Items_desc.get(i);
            str_UOM[i]          = Items_uom.get(i);
            str_Parlevel[i]     = Items_perunitcost.get(i);

            str_Openingstock[i] = "";
            str_Reg[i]          = "";
            str_Intertransfer[i] = "";
            str_Closingstock[i] = "";
            str_Remark[i]       = "";

            //System.out.println("str_Idoriginal  "+str_Idoriginal[i]);

        }


        lInflater = (LayoutInflater) ctx
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);


        notifyDataSetChanged();



    }

    @Override
    public int getCount() {
        return Data_id.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }



    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {


         final ViewHolder holder;

        /*if (convertView == null) {
            convertView = (View) lInflater.inflate(R.layout.baradmin_row, parent, false);           
        }*/

        if (convertView == null) {
            holder = new ViewHolder();
            //convertView = (View)lInflater.inflate(R.layout.baradmin_row, null);
            convertView = (View) lInflater.inflate(R.layout.baradmin_row, parent, false);

            //holder  = new ViewHolder();


            holder.editText_id                      = (EditText) convertView.findViewById(R.id.edittext_slno_baradmin);
            holder.editText_desc                    = (EditText) convertView.findViewById(R.id.edittext_desc_baradmin);
            holder.editText_uom                     = (EditText) convertView.findViewById(R.id.edittext_uom_baradmin);
            holder.editText_parlevel                = (EditText) convertView.findViewById(R.id.edittext_parlevel_baradmin);
            holder.edittext_openingstock_baradmin   = (EditText) convertView.findViewById(R.id.edittext_openingstock_baradmin);
            holder.edittext_reg_baradmin            = (EditText) convertView.findViewById(R.id.edittext_reg_baradmin);
            holder.edittext_intertransfer_baradmin  = (EditText) convertView.findViewById(R.id.edittext_intertransfer_baradmin);
            holder.edittext_closingstock_baradmin   = (EditText) convertView.findViewById(R.id.edittext_closingstock_baradmin);
            holder.edittext_remark_baradmin         = (EditText) convertView.findViewById(R.id.edittext_remark_baradmin);




            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        try {


            holder.editText_id          .setText(position+1+"");
            holder.editText_desc        .setText(Data_name.get(position));
            holder.editText_uom         .setText(Data_uom.get(position));
            holder.editText_parlevel    .setText(Data_parlevel.get(position));

            holder.edittext_openingstock_baradmin.setOnFocusChangeListener(new OnFocusChangeListener() {
                public void onFocusChange(View v, boolean hasFocus) {
                    if (!hasFocus){
                        //final int position = v.getId();
                        final EditText Caption = (EditText) v;

                        str_Openingstock[position] = holder.edittext_openingstock_baradmin.getText().toString();

                    }
                }
            });


            holder.edittext_reg_baradmin.setOnFocusChangeListener(new OnFocusChangeListener() {
                public void onFocusChange(View v, boolean hasFocus) {
                    if (!hasFocus){

                        str_Reg[position] = holder.edittext_reg_baradmin.getText().toString();

                    }
                }
            });

            holder.edittext_intertransfer_baradmin.setOnFocusChangeListener(new OnFocusChangeListener() {
                public void onFocusChange(View v, boolean hasFocus) {
                    if (!hasFocus){

                        str_Intertransfer[position] = holder.edittext_intertransfer_baradmin.getText().toString();
                    }
                }
            });

            holder.edittext_closingstock_baradmin.setOnFocusChangeListener(new OnFocusChangeListener() {
                public void onFocusChange(View v, boolean hasFocus) {
                    if (!hasFocus){

                        str_Closingstock[position] = holder.edittext_closingstock_baradmin.getText().toString();


                        //strings[position] = holder.edittext_openingstock_baradmin.getText().toString();
                    }
                }
            });

            holder.edittext_remark_baradmin.setOnFocusChangeListener(new OnFocusChangeListener() {
                public void onFocusChange(View v, boolean hasFocus) {
                    if (!hasFocus){
                        //final int position = v.getId();
                        final EditText Caption = (EditText) v;

                        str_Remark[position] = holder.edittext_remark_baradmin.getText().toString();
                    }
                }
            });


        } catch (Exception e) {
            // TODO: handle exception
        }


        return convertView;
    }
    class ViewHolder {
        EditText editText_id, editText_desc, editText_uom, editText_parlevel,
                edittext_openingstock_baradmin, edittext_reg_baradmin, edittext_intertransfer_baradmin,
                edittext_closingstock_baradmin, edittext_remark_baradmin;
    }

    class ListItem {
        String caption;
    }
}

在logcat中我可以看到 02-12 14:51:04.164:I / Editor(18219):设置窗口支持句柄

2 个答案:

答案 0 :(得分:0)

您是否尝试在列表视图中设置此属性

android:descendantFocusability="beforeDescendants"

答案 1 :(得分:0)

我建议你听一下onfocusChange的活动而不是听每个编辑框,这可能会删除闪烁(而是执行所有编辑框onfcoucs更改方法,它已被捕获一次。)

 @Override
 public void onFocusChange(View v, boolean hasFocus) {
    switch(v.getId()){
      case r.id.editText_id:
       break;
    }
  }