嗨,我正在制作whatsapp清洁应用程序。 这是我的适配器类
public class CustomAdapter extends BaseAdapter {
Context c;
ArrayList<Spacecraft> spacecrafts;
public CustomAdapter(Context c, ArrayList<Spacecraft> spacecrafts) {
this.c = c;
this.spacecrafts = spacecrafts;
}
@Override
public int getCount() {
return spacecrafts.size();
}
@Override
public Object getItem(int i) {
return spacecrafts.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View v=null;
LayoutInflater inflater = (LayoutInflater)c
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(view==null)
{//INFLATE CUSTOM LAYOUT
v = new View(c);
v = inflater.inflate(R.layout.whatsimage, null);
final Spacecraft s= (Spacecraft) this.getItem(i);
TextView nameTxt= (TextView) v.findViewById(R.id.textView);
ImageView img= (ImageView) v.findViewById(R.id.image);
//BIND DATA
nameTxt.setText(s.getName());
Picasso.get().load(s.getUri()).into(img);
//VIEW ITEM CLICK
}
else {
v = (View) view;
}
return v;
}
}
这是我的物品类别。
public class Spacecraft {
String name;
private Uri uri;;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Uri getUri() {
return uri;
}
public void setUri(Uri uri) {
this.uri = uri;
}
}
我正在使用gv.Multiplechoice进行选择,但是当我单击项目时,项目不会突出显示。 我想在单击时突出显示图像。 我是android编程的新手,所以我不知道该如何实现? 谁能帮助我,并提供更好的解决方案。
gv.setAdapter(adapter);
gv.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
gv.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
count=count+1;
mode.setTitle(count+" Deleted Items");
list_items.add(list.get(position));
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater=mode.getMenuInflater();
inflater.inflate(R.menu.menu_main,menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.action_open:
int i;
for ( i= 0; i < list_items.size(); ++i) {
Spacecraft s1 = list_items.get(i);
File f = new File(s1.getUri().getPath());
Boolean deleted = f.delete();
GridViewLayout.this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(s1.getUri().getPath()))));
if (deleted == true) {
list_items.remove(i);
list.remove(s1);
adapter.notifyDataSetChanged();
}
}
Toast.makeText(GridViewLayout.this, count +"Deleted", Toast.LENGTH_SHORT).show();
count=0;
mode.finish();
return true;
default: return false;
}
}
@Override
public void onDestroyActionMode(ActionMode mode) {
}
答案 0 :(得分:0)
也许您可以在Spacecraft中添加标志isSelected属性以在CustomAdapter中使用。您可以看到一些东西来显示基于isSelected标志的边框
更改标志后,您需要先通知数据集更改。