我正在开发一个Android应用程序,我必须显示一个包含重复项目的列表视图。最初列表视图显示3个项目,但我希望它们显示3或4次。有没有办法做到这一点?
public class CustomAdapter extends ArrayAdapter<HireGroups> {
ArrayList<HireGroups> result;
Context c;
LayoutInflater inflater;
public CustomAdapter(Context context, ArrayList<HireGroups> list) {
super(context,0, list);
c=context;
result=list;
inflater = ( LayoutInflater )context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return result.size();
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public boolean isEnabled(int position) {
final HireGroups h = result.get(position);
if(h.getSubHireGroup().size() == 0) {
return false;
}
return super.isEnabled(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v=convertView;
final HireGroups i = result.get(position);
if(i != null) {
v = inflater.inflate(R.layout.single_hiregroup_item, null);
final TextView hireGroupName = (TextView) v.findViewById(R.id.hire_group_name);
final TextView subtitle = (TextView) v.findViewById(R.id.subtitle);
final TextView desc = (TextView) v.findViewById(R.id.hire_group_desc);
final ImageView hiregroupImage = (ImageView) v.findViewById(R.id.hire_group_image);
final TextView vehicleCount = (TextView) v.findViewById(R.id.no_of_vehicles);
if(hireGroupName != null) {
hireGroupName.setText(i.getHireGroupName());
}
if(subtitle != null) {
subtitle.setText(i.getSubTitle());
}
if(hiregroupImage != null) {
Picasso.with(c).load(i.getPhotoUrl()).into(hiregroupImage);
}
if(desc != null) {
desc.setText(i.getDescription());
}
if(vehicleCount != null)
{
int count=i.getSubHireGroup().size();
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(200); //You can manage the blinking time with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
if(count > 0)
{
vehicleCount.startAnimation(anim);
vehicleCount.setText(" "+count+" Available ");
}
else
vehicleCount.setText(" "+count+" Available ");
}
}
return v;
}
}
答案 0 :(得分:0)
假设您想要显示相同的数据3次,那么您可以做的是
像这样修改 getCount()
@Override
public int getCount() {
return result.size() * 3;
}
并修改 getView()
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v=convertView;
final HireGroups i = result.get(position % 3);
if(i != null) {
v = inflater.inflate(R.layout.single_hiregroup_item, null);
final TextView hireGroupName = (TextView) v.findViewById(R.id.hire_group_name);
final TextView subtitle = (TextView) v.findViewById(R.id.subtitle);
final TextView desc = (TextView) v.findViewById(R.id.hire_group_desc);
final ImageView hiregroupImage = (ImageView) v.findViewById(R.id.hire_group_image);
final TextView vehicleCount = (TextView) v.findViewById(R.id.no_of_vehicles);
if(hireGroupName != null) {
hireGroupName.setText(i.getHireGroupName());
}
if(subtitle != null) {
subtitle.setText(i.getSubTitle());
}
if(hiregroupImage != null) {
Picasso.with(c).load(i.getPhotoUrl()).into(hiregroupImage);
}
if(desc != null) {
desc.setText(i.getDescription());
}
if(vehicleCount != null)
{
int count=i.getSubHireGroup().size();
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(200); //You can manage the blinking time with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
if(count > 0)
{
vehicleCount.startAnimation(anim);
vehicleCount.setText(" "+count+" Available ");
}
else
vehicleCount.setText(" "+count+" Available ");
}
}
return v;
}