나는 내 listview를 제어하기 위해 사용자 정의 어댑터 클래스를 구현했다. 나는 단추, 텍스트 상자 및 목록보기의 각 행에 대한 체크 박스를 구현하고있다. 목록보기의 일부가 아닌 두 개의 단추가 있습니다. 그들은 listview 아래에 있습니다. 이제 상자 수를 확인하고 목록보기에 포함되지 않은 단추를 누르면 확인란이있는 경우 확인란을 삭제할 수 있기를 원합니다. 즉, 목록보기에 포함되지 않은 버튼을 클릭하여 체크 된 항목을 삭제할 수 있습니다.체크 박스와 버튼을 사용한 사용자 정의 목록보기 구현. 안드로이드
여기 내 주요 클래스의 ... 행이 기본적으로 그렇게 모두 모두 동영상으로 채워집니다
public class AScustomadapter extends BaseAdapter {
private ArrayList<String> mListItems;
private LayoutInflater mLayoutInflater;
int i = 0;
private ArrayList<Integer> checkedIndices = new ArrayList<Integer>();
public AScustomadapter(Context context, ArrayList<String> arrayList) {
mListItems = arrayList;
//get the layout inflater
mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mListItems.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
public int getTotalCheckedCount() {
return checkedIndices.size();
}
@Override
public View getView(final int position, View view, ViewGroup viewGroup) {
ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = mLayoutInflater.inflate(R.layout.list_item, null);
holder.itemName = (TextView) view.findViewById(R.id.list_item_text_view);
holder.cb1 = (CheckBox) view.findViewById(R.id.checkBox1);
view.setTag(holder);
} else {
holder = (ViewHolder)view.getTag();
}
final String stringItem = mListItems.get(position);
if (stringItem != null) {
if (holder.itemName != null) {
holder.itemName.setText(stringItem);
}
}
holder.cb1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
if(checkedIndices.contains(position)){
}else {
checkedIndices.add(position);
}
}else {
checkedIndices.remove((Integer)position);
}
}
});
if(checkedIndices.contains((Integer)position)) {
holder.cb1.setChecked(true);
} else {
holder.cb1.setChecked(false);
}
//this method must return the view corresponding to the data at the specified position.
return view;
}
private static class ViewHolder {
protected TextView itemName;
protected CheckBox cb1;
}
}
public class ASvideofiles extends Activity implements OnClickListener {
int count = 0;
private String[] vidNames;
private String[] vidPaths;
private ListView myList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.asvideofiles);
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(this);
Button b2 = (Button) findViewById(R.id.button2);
b2.setOnClickListener(this);
File f = new File(Environment.getExternalStorageDirectory(),
"ABC/XYZ/");
File[] files = f.listFiles();
vidNames = new String[files.length];
vidPaths = new String[files.length];
if(files != null) {
for(int i=0; i < files.length; i++) {
vidNames[i] = files[i].getName();
vidPaths[i] = files[i].getPath();
count ++;
}
}
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < files.length; i++) {
list.add(vidNames[i]);
}
myList = (ListView)findViewById(R.id.listView1);
myList.setAdapter(new AScustomadapter(ASvideofiles.this, list));
}
@Override
public void onClick(View v) {
if(v.getId() == R.id.button1) {
} else if(v.getId() == R.id.button2) {
}
}
}
여기 내 어댑터 클래스의이 ..., 나는 할 수 있도록하려면 확인란을 선택하고 삭제 버튼을 눌러 선택한 비디오를 삭제합니다. 도움이 필요합니다. 미리 감사드립니다.
클릭 전화 모두 일치 클릭? 버튼 클릭시 체크 박스를 선택 해제 하시겠습니까? –
아니요, 죄송합니다. 확인란을 선택하고 삭제 버튼을 누른 전체 행을 삭제하고 싶습니다. –
답변을 게시했습니다. 그것은 올바르게 작동하고있다 –