2016-05-23 15 views
0

私はeditTextを最初の位置でのみ無効にしたいリストビューを持っています。これは私がやったことです:アンドロイドは特定の位置のリストビューでeditTextを無効にします

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 

    final PatientView patientView; 

    if(convertView==null){ 
     LayoutInflater inflater=LayoutInflater.from(context); 
     convertView=inflater.inflate(R.layout.lay_add_session_view,null); 
     patientView=new PatientView(); 
     patientView.edtSessionDescription= (EditText) convertView.findViewById(R.id.edtSessionDescription); 
     patientView.edtSessionNumber= (EditText) convertView.findViewById(R.id.edtSessionNumber); 
     patientView.txtSessionTime= (TextView) convertView.findViewById(R.id.txtSessionTime); 
     patientView.btnAdd= (Button) convertView.findViewById(R.id.btnAdd); 
     patientView.btnDelete= (Button) convertView.findViewById(R.id.btnDelete); 

     convertView.setTag(patientView); 
    } else { 
     patientView= (PatientView) convertView.getTag(); 
    } 

    patientView.edtSessionNumber.setText(modelPatientArrayList.get(position).getSessionNumber()); 
    patientView.edtSessionNumber.setTag(position); 
    patientView.edtSessionDescription.setText(modelPatientArrayList.get(position).getSessionDescription()); 
    patientView.txtSessionTime.setText(modelPatientArrayList.get(position).getTime()); 



    if(0==(Integer)patientView.edtSessionNumber.getTag()){ 
     patientView.edtSessionNumber.setEnabled(false); 
    } 

    patientView.btnAdd.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Log.e("tag position",(Integer) patientView.edtSessionNumber.getTag()+""); 
      updateFirstSession(modelPatientArrayList.get(position), patientView.edtSessionDescription.getText().toString()); 

      modelPatientArrayList.clear(); 
      modelPatientArrayList.addAll(dbUtil.getPatientSession()); 
      patientView.btnAdd.setText("edit"); 
      patientView.btnAdd.setTag(position); 
      notifyDataSetChanged(); 

     } 
    }); 

    patientView.btnDelete.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      deleteFromDataBase(modelPatientArrayList.get(position)); 
      modelPatientArrayList.clear(); 
      modelPatientArrayList.addAll(dbUtil.getPatientSession()); 
      notifyDataSetInvalidated(); 
     } 
    }); 

    return convertView; 
} 

しかし、問題は、スクロール後に他のビューのedittextを無効にすることです。誰でも私が間違っていることを教えてください。

答えて

0

ListViewコントロールを使用すると、両方のケース

patientView.edtSessionNumber.setEnabled((position == 0) ? false : true); 

happyCodingためのコードを記述する必要があるので、ビューを再使用するので、

+0

ありがとう – Shaan

0

このコードを入力すると、プロンプトが解決するはずです。 if(position == 0) patientView.edtSe​​ssionNumber.setEnabled(false);

+0

私は試してみましたが、7つの位置を無効にしていますedittext – Shaan

+0

patientView.edtSe​​ssionNumber.setTag(position); convertViewの初期化の中で –

関連する問題