ここではlistitem
を選択し、その特定のアイテムの色が変更されています。 2回目にアイテムを選択すると、この前のアイテムがキャンセルされ、新しいアイテムの色を変更する必要があります。リスト項目の値を1つだけ選択する必要があります
delivery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater1 = (LayoutInflater) ct.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v1 = inflater1.inflate(R.layout.activity_employees_list_for_pop_up, null);
final Button ok = (Button) v1.findViewById(R.id.do_ok);
Button cancle = (Button) v1.findViewById(R.id.do_cancle);
final TextView empId=(TextView)v1.findViewById(R.id.employeeId);
ok.setEnabled(false);
listView = (ListView) v1.findViewById(R.id.employeePopUpList);
employeePopUpAdapter = new EmployeePopUpAdapter(ct, employeeIdNameBeans);
//enable ok button if listitem is checked
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ok.setEnabled(true);
//Toast.makeText(ct, ""+employeeIdNameBeans.get(position).getEmpId(), Toast.LENGTH_SHORT).show();
view.setBackgroundColor(Color.GREEN);
selectedemployeeid=employeeIdNameBeans.get(position).getEmpId();
}
});
そして、色を変更した特定のemployeeidを取得する必要があります。
とアダプタクラスで私はちょうど値にEMPIDとのempName
public class EmployeePopUpAdapter extends BaseAdapter {
Context ct;
private List<EmployeeIdNameBean> employeeIdNameBeans;
private int lastPosition = -1;
public EmployeePopUpAdapter(Context ct, List<EmployeeIdNameBean> employeeIdNameBeans) {
this.ct = ct;
this.employeeIdNameBeans = employeeIdNameBeans;
}
@Override
public int getCount() {
return employeeIdNameBeans.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) ct.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.list_view_for_employee_popup_window, null);
TextView empId = (TextView) v.findViewById(R.id.employeeId);
TextView empName = (TextView) v.findViewById(R.id.empFullName);
//For animation
Animation animation = AnimationUtils.loadAnimation(ct, (position > lastPosition) ? R.anim.top_from_bottom : R.anim.down_from_top);
v.startAnimation(animation);
lastPosition = position;
final EmployeeIdNameBean empbean = employeeIdNameBeans.get(position);
empId.setText(empbean.getEmpId());
empName.setText(empbean.getEmpName());
return v;
}
}
アドパターコードも投稿してください。この目的のために、選択した明細ポジションを更新する必要があります。 –
@ R.R.Mアダプタクラスも追加しました。コードを確認して返信してください。前もってありがとうございます – aaron