2014-01-28 70 views
1

我有自定義模板與edittext字段。當我點擊軟鍵盤上的「下一步」按鈕時,它只移動兩次焦點 - 比按鈕更改爲「確定」。列表有12個項目。 任何方式導航到所有項目,不僅2? 你能幫我嗎?listview和edittext softkeyboard

即時通訊使用這個模板列表視圖:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:padding="3dp" > 

    <TextView 
     android:id="@+id/head" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:baselineAligned="true" 
     android:paddingBottom="3dp" 
     android:paddingTop="3dp" > 

     <EditText 
      android:id="@+id/value" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:ems="10" 
      android:gravity="left" 
      android:inputType="number" > 

      <requestFocus /> 
     </EditText> 

     <TextView 
      android:id="@+id/description" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:width="100dp" /> 

    </LinearLayout> 

</LinearLayout> 

而這個XML爲列表視圖:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/head" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/calk_1" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="match_parent" 
     android:layout_height="382dp" 
     android:divider="@color/reddivider" 
     android:dividerHeight="@dimen/twodp" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:smoothScrollbar="true" > 

    </ListView> 

</LinearLayout> 

而且,在這裏我的適配器現在:

公共查看getView(INT位置,查看convertView,ViewGroup父){

// assign the view we are converting to a local variable 
View v = convertView; 

// first check to see if the view is null. if so, we have to inflate it. 
// to inflate it basically means to render, or show, the view. 
if (v == null) { 
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    v = inflater.inflate(R.layout.list_view, null); 
} 

/* 
* Recall that the variable position is sent in as an argument to this method. 
* The variable simply refers to the position of the current object in the list. (The ArrayAdapter 
* iterates through the list we sent it) 
* 
* Therefore, i refers to the current Item object. 
*/ 
CalcItem i = objects.get(position); 
int last=getCount()-1; 

if (i != null) { 

    // This is how you obtain a reference to the TextViews. 
    // These TextViews are created in the XML files we defined. 

    TextView hd = (TextView) v.findViewById(R.id.head); 
    TextView tx = (TextView) v.findViewById(R.id.text); 
    TextView ds = (TextView) v.findViewById(R.id.description); 
    EditText vl = (EditText) v.findViewById(R.id.value); 

    if (position==0){ 
     vl.setNextFocusUpId(last); 
     vl.setNextFocusDownId(1); 
    } else if (position==last){ 
     vl.setNextFocusDownId(0); 
    } else { 
     vl.setNextFocusDownId(position+1); 
    } 

    if (hd != null){ 
     hd.setText(i.getHead()); 
    } 
    if (tx != null){ 
     tx.setText(i.getText()); 
    } 
    if (ds != null){ 
     ds.setText(i.getDescription()); 
    } 
    if (vl != null){ 
     vl.setText(Integer.toString(i.getValue())); 
    } 
} 

// the view must be returned to our activity 
return v; 

}

回答

0

android:nextFocusUp="id"使用和android:nextFocusDown="id" - 如在documentation說明。

下面是從文檔的例子:

<LinearLayout 
    android:orientation="vertical" 
    ... > 
    <Button android:id="@+id/top" 
      android:nextFocusUp="@+id/bottom" 
      ... /> 
    <Button android:id="@+id/bottom" 
      android:nextFocusDown="@+id/top" 
      ... /> 
</LinearLayout> 
+0

謝謝。我更改我的適配器代碼,但沒有任何 - 它不工作。我更新了我的問題 –

+0

您是否需要使用listview - 或者因爲您知道總是隻有12個項目,所以可以滾動視圖? – Submersed

+0

我有兩項活動與不同的項目數。其中有23個物品和30個其他物品。在拍攝將來,還可以改變物品數量。 –