出现键盘时带有edittext问题的Listview

时间:2014-08-22 08:21:08

标签: android listview android-listview

enter image description here

我正在使用自定义列表视图和编辑文本

当我点击listview的最后一个编辑文本时,所有完整活动都滚动到了

但我想在键盘出现时只滚动listview

enter image description here

我的自定义列表视图的java代码

class CreateAdapter extends ArrayAdapter<String>  {
        String[] strItecode=null;
        String[] strItem;
        String[] strQuantity;
        Context context;

        int temp;
        CreateAdapter(Context context, String[] strItemcode, String[] strItem,
                String[] strQauntity) {
            super(context, R.layout.create_list_item, R.id.txtItemcode, strItemcode);
            this.context = context;
            this.strItecode = strItemcode;
            this.strItem = strItem;
            this.strQuantity = strQauntity;
           // text= new String[strItem.length];
        }
        private int editingPosition = 0;
        private TextWatcher watcher = new TextWatcher() {
                  public void onTextChanged(CharSequence s, int start, int before, int count) {
                      text[editingPosition] = s.toString();
                  }
                  public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
                  public void afterTextChanged(Editable s) { }
              };

        public View getView( final int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            temp=position;
            LayoutInflater mInflater = (LayoutInflater) context
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            if (convertView == null) {

                holder = new ViewHolder();
                convertView = mInflater
                        .inflate(R.layout.create_list_item, parent, false);

                holder.txtItecode = (TextView) convertView
                        .findViewById(R.id.txtItemcode);
                holder.txtItem = (TextView) convertView
                        .findViewById(R.id.txtItem);
                holder.editQuantity = (EditText) convertView
                        .findViewById(R.id.editcreateQuantity);
                holder.editQuantity.setTag(position);

                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.editQuantity.removeTextChangedListener(watcher);
           if(text[temp].contentEquals("0"))
               holder.editQuantity.setText("");
           else
            holder.editQuantity.setText(text[temp]);

            holder.editQuantity.setOnFocusChangeListener(new OnFocusChangeListener() {       
                public void onFocusChange(View v, boolean hasFocus) {
                  if(hasFocus) editingPosition = position;
                }
            });

            holder.editQuantity.addTextChangedListener(watcher);

            // The rest is good, just make sure to remove the call to setting the EditText's text at the end
            holder.txtItecode.setText(strItecode[position]);
            holder.txtItem.setText(strItem[position]);
          //  holder.editQuantity.setText(text[temp]);
            return convertView;


        }

        class ViewHolder {
            TextView txtItecode;
            TextView txtItem;
            EditText editQuantity;
        }
    }

此活动的清单代码

  <activity android:name=".CreateChallan" android:label="@string/app_name"
             android:screenOrientation="portrait"

             android:windowSoftInputMode="adjustPan" />

请帮助我如何在键盘出现时设置仅滚动列表视图而不是完整活动

提前致谢

我真的很抱歉我的英语不好

1 个答案:

答案 0 :(得分:0)

这可能会有所帮助。

使用: android:windowSoftInputMode="adjustResize"

如果您更改此布局结构:

    <LinearLayout
        android:id="@+id/text_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
         //other view if you have any..

        <ListView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

</LinearLayout>

它将显示完整的列表视图并重叠其他视图。