我有一个自定义 Gridview 来显示操作员列表及其图标和提供者的名称。我的问题是 Gridview 仅显示有限的提供者(仅 12 个)。但是要显示的值超过 16 个。剩余值正在重复在 Gridview 中滚动 GridView。
我的源代码在这里
public class ImageAdapter extends BaseAdapter {
public int getCount() {
return providerlist1.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
View v;
ImageView imageView;
if (convertView == null) {
LayoutInflater layoutInflater = getLayoutInflater();
v = layoutInflater.inflate(R.layout.icon_with_text, null);
TextView txt = (TextView) v.findViewById(R.id.icon_text);
txt.invalidate();
txt.setTypeface(localTypeface1);
Collections.sort(providerlist1);
Log.v("COLLECTIONS", ""+providerlist1);
txt.setText("" + providerlist1.toArray()[position]);
String string = (String) txt.getText();
icon = string.toLowerCase();
System.out.println(icon);
int resid = getResources().getIdentifier("" + icon, "drawable",
"com.digient.yeldi.app");
imageView = (ImageView) v.findViewById(R.id.icon_image);
imageView.setImageResource(resid);
} else {
v = convertView;
}
return v;
}
}
providerlist1 是一个数组列表,其中有超过 16 个操作符值。