2012-04-18 13 views
1

私はAndroid 3.1アプリケーションを開発しています。私はAndroid開発で非常に新しいです。ここでArrayAdapter:getView引数の変数がfinalに変更されました

は、リストビューで使用するカスタム・アレイ・アダプタです:public View getView(int position, View convertView, ViewGroup parent)

public class FormAdapter extends ArrayAdapter<Form> 
{ 
    private Context context; 
    private int layoutResourceId; 
    private List<Form> forms; 
    public ArrayList<String> checkedItems; 
    private Button downloadButton; 

    public ArrayList<String> getCheckedItems() 
    { 
     return checkedItems; 
    } 

    public FormAdapter(Context context, int textViewResourceId, 
      List<Form> objects, Button downloadButton) 
    { 
     super(context, textViewResourceId, objects); 

     this.context = context; 
     this.layoutResourceId = textViewResourceId; 
     this.forms = objects; 
     this.checkedItems = new ArrayList<String>(); 
     this.downloadButton = downloadButton; 
    } 

    @Override 
    public View getView(final int position, View convertView, ViewGroup parent) 
    { 
     View row = convertView; 
     if (row == null) 
     { 
      LayoutInflater inflater = ((Activity)context).getLayoutInflater(); 
      row = inflater.inflate(layoutResourceId, parent, false); 
     } 

     Form f = forms.get(position); 
     if (f != null) 
     { 
      CheckBox checkBox = (CheckBox)row.findViewById(R.id.itemCheckBox); 
      if (checkBox != null) 
      { 
       checkBox.setText(f.Name); 
       checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() 
       { 
        public void onCheckedChanged(CompoundButton buttonView, 
          boolean isChecked) 
        { 
         Form f = forms.get(position); 
         if (isChecked) 
         { 
          checkedItems.add(f.FormId); 
         } 
         else 
         { 
          checkedItems.remove(checkedItems.indexOf(f.FormId)); 
         } 
         downloadButton.setEnabled(checkedItems.size() > 0); 
        } 
       }); 
      } 
     } 

     return row; 
    } 
} 

私は最終position引数に変更する必要があります。 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)メソッドで使用する必要があるので、私はそれを行った。

positionに変更すると問題はありますか?? にpositionを使用する他の方法はありますか?

答えて

2

問題ありません。あなたは、これはOKですgetViewメソッドでそれに任意の値を代入していないので

position = ... 

:変数または最後のパラメータを作ることは、あなたがのように、それに値を再割り当てすることができないことを意味します。

1

いいえありません。通常positionは、その特定の位置のアイテムをどのように作成するかを定義するために使用されます。私はまだgetView()で位置が変更されているのを見ていません。だからあなたはそれをするのが安全です。

2

VansFannelは実際には最終として宣言する必要はありません。最終変更子は、変数の値を変更したくない場合にのみ必要です。

関連する問題