1
강조 표시된 텍스트 안녕하세요 여러분 모두 안드로이드 맞춤 목록보기를 확인란 예제와 함께 작동합니다. 그러나 나는이 예를했다. 목록 행을 클릭하면 해당 확인란이 선택됩니다. 그러나 내 listview 스크롤 하단 - 가기, 선택한 확인란을 변경합니다. 도와주세요. 모두에게 감사드립니다. 활동에 의해 내 코드Android Custom Listview 체크 박스 스크롤
public class YoklamaListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
public List<MovieYoklama> yoklamaItems;
boolean selected = false;
private int selectedPosition = -1;
private int selectedStart = 0;
public YoklamaListAdapter(Activity activity, List<MovieYoklama> movieItems) {
this.activity = activity;
this.yoklamaItems = movieItems;
}
@Override
public int getCount() {
return yoklamaItems.size();
}
@Override
public Object getItem(int location) {
return yoklamaItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.listturyoklama_row, null);
ImageView thumbNail = (ImageView) convertView
.findViewById(R.id.thumbnailYoklama);
TextView title = (TextView) convertView
.findViewById(R.id.txtYoklamaTitle);
TextView kisiID = (TextView) convertView
.findViewById(R.id.txtYoklamaKID);
TextView kisiTip = (TextView) convertView
.findViewById(R.id.txtYoklamaKTip);
CheckBox chk = (CheckBox) convertView.findViewById(R.id.chckYoklama);
MovieYoklama m = yoklamaItems.get(position);
if (selectedStart == 0) {
chk.setChecked(true);
m.setCheckbox(true);
} else {
if (position == selectedPosition) {
if (!m.isCheckbox()) {
chk.setChecked(true);
m.setCheckbox(true);
} else {
chk.setChecked(false);
m.setCheckbox(false);
}
}
}
thumbNail.setImageResource(m.getThumbnailUrl());
// title
title.setText(m.getTitle());
// ID
kisiID.setText(m.getID());
// Tip
kisiTip.setText(m.getTip());
return convertView;
}
public void setCheckBox(int position) {
selectedPosition = position;
selectedStart = 1;
notifyDataSetChanged();
}
}
내 MovieYoklama 클래스
public class MovieYoklama {
private String title, ID, Tip;
int thumbnailUrl;
private boolean checkbox;
public MovieYoklama() {
}
public MovieYoklama(String name, int thumbnailUrl, boolean checkbox,
String ID, String Tip) {
this.title = name;
this.thumbnailUrl = thumbnailUrl;
this.checkbox = checkbox;
this.ID = ID;
this.Tip = Tip;
}
public String getTitle() {
return title;
}
public void setTitle(String name) {
this.title = name;
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public String getTip() {
return Tip;
}
public void setTip(String Tip) {
this.Tip = Tip;
}
public int getThumbnailUrl() {
return thumbnailUrl;
}
public void setThumbnailUrl(int thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
}
public boolean isCheckbox() {
return checkbox;
}
public void setCheckbox(boolean checkbox) {
this.checkbox = checkbox;
}
}
다음 목록보기를 클릭하여 항목을 클릭 할 때 당신은 MovieYoklama 개체를 업데이트해야
private YoklamaListAdapter adapteryoklama;
----------
listViewYoklama.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
adapteryoklama.setCheckBox(position);
}
});
다음을 읽을 수 있습니다. http://www.mysamplecode.com/2012/07/android-listview-checkbox-example.html –