我沿着code here (weblink).阅读并且代码已被修改了一点,变成这样:
FileArrayAdapter.java
public class FileArrayAdapter extends ArrayAdapter- stemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(id,null);
}
/* create a new view of my layout and inflate it in the row */
// convertView = ( RelativeLayout ) inflater.inflate( resource,null );
final Item o = items.get(position);
if (o != null) {
TextView t1 = (TextView) v.findViewById(R.id.TextView01);
setDefaultTextColor(t1);
TextView t2 = (TextView) v.findViewById(R.id.TextView02);
setDefaultTextColor(t2);
TextView t3 = (TextView) v.findViewById(R.id.TextViewDate);
setDefaultTextColor(t3);
/* Take the ImageView from layout and set the city's image */
ImageView imageCity = (ImageView) v.findViewById(R.id.fd_Icon1);
String uri = "drawable/" + o.getimage();
int imageResource = c.getResources().getIdentifier(uri,null,c.getPackageName());
Drawable image = c.getResources().getDrawable(imageResource);
imageCity.setimageDrawable(image);
if (t1 != null)
t1.setText(o.getName());
if (t2 != null)
t2.setText(o.getData());
if (t3 != null)
t3.setText(o.getDate());
}
return v;
}
private void setDefaultTextColor(TextView tx) {
tx.setTextColor(Color.parseColor("#f8f9fe"));
}
}
还有我到目前为止做的另一个目标:
Item.java
public class Item implements Comparable- timage() {
return image;
}
public int compareto(Item o) {
if(this.name != null)
return this.name.toLowerCase().compareto(o.getName().toLowerCase());
else
throw new IllegalArgumentException();
} }
列表布局有点定制如下:
listupload_row.xml
我的问题是:
我知道如果我想放置CheckBox,那么我应该把它放在XML(布局)下面.
但我的情况是,我想让longClick可用于显示CheckBoxes.
怎么做?
如果我只是在下面添加这个代码,当然它会将ListView设置为onLongClick事件….
dList.setLongClickable(true);
dList.setonItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView> arg0,View arg1,int pos,long id) {
// show the checkBox of each lines
return true;
}
});
但是为了让它一旦亮起执行,我如何展示ComboBox?反之亦然….
最佳答案
一种可能的解决方案是隐藏/显示复选框,该复选框基于当项目收到长按时切换的标志.
在适配器的getView方法中执行以下操作:
在适配器的getView方法中执行以下操作:
@Override
public View getView(int position,ViewGroup parent) {
...
if(showCheckBoxes) {
v.findViewById(R.id.checkBox).setVisible(View.VISIBLE);
} else {
v.findViewById(R.id.checkBox).setVisible(View.GONE);
}
...
}
然后在你的长按监听器中:
dList.setonItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView> arg0,long id) {
showCheckBoxes = !showCheckBoxes;
fileArrayAdapter.notifyDataSetChanged();
return true;
}
});