首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >带有编辑文本的列表视图-出现键盘时自动滚动

带有编辑文本的列表视图-出现键盘时自动滚动
EN

Stack Overflow用户
提问于 2014-08-29 15:26:21
回答 2查看 577关注 0票数 0

我有一个编辑文本在每一列表视图行,我想自动滚动时,键盘出现

我已经在我的menifetch.xml中添加了这个代码android:windowSoftInputMode="adjustPan|stateHidden",但是没有起作用

我的getview java代码

//创建列表适配器

代码语言:javascript
复制
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;
}

}

请告诉我如何设置当键盘出现时自动滚动

提前感谢

EN

回答 2

Stack Overflow用户

发布于 2014-08-29 15:39:50

尝尝这个

Activity中的

代码语言:javascript
复制
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int proposedheight = MeasureSpec.getSize(heightMeasureSpec);
    final int actualHeight = getHeight();

    if (actualHeight > proposedheight){
        scrollMyListViewToBottom();
    }  

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

private void scrollMyListViewToBottom() {
    myListView.post(new Runnable() {
        @Override
        public void run() {
            // Select the last row so it will scroll into view...
            myListView.setSelection(myListAdapter.getCount() - 1);
        }
    });
}
票数 0
EN

Stack Overflow用户

发布于 2018-06-21 07:41:34

在您的Activity中尝试此操作

代码语言:javascript
复制
listview.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25563516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档