2014-08-29 65 views
0

我有充分的ListView行的編輯文本,我想列表視圖與編輯文本 - 自動滾動時出現鍵盤

我加入這個代碼Android的鍵盤出現自動滾屏:windowSoftInputMode =「adjustPan | stateHidden」我menifetch.xml但沒有奏效

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

}

請幫我如何可以設置自動滾屏當鍵盤出現

在此先感謝

回答

0

試試這個

您的活動

@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

我怎麼能在我們的活動中使用此代碼 – user3886688 2014-08-29 07:42:19

+0

我希望它能幫助你 – Davide 2014-08-29 07:46:53

+0

變化e函數'scrollMyListViewToBottom'在你的'listview'中指定一個特定的位置作爲正在被編輯的項目 – Davide 2014-08-29 07:52:57

相關問題