我的自定义ArrayAdapter中的getView方法被多次调用,我认为这是有意的.问题是,我有一个动态设置的数量TextView但是当你滚动并且框离开屏幕时,该值消失.我不确定我做错了什么,Google并没有证明它有多大帮助.希望有人在这里可以帮助我.
适应器称为:
adapter = new MenuAdapter(thisActivity, R.layout.menu, list);
setListAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
我的自定义ArrayAdapter:
public MenuAdapter(Context context, int textViewResourceId, ArrayList<Object> menu) {
super(context, textViewResourceId, menu);
this.menu = menu;
vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
Object cat = menu.get(position);
if (cat.getClass().equals(Category.class)) {
v = vi.inflate(R.layout.category, null);
Category item = (Category)cat;
v.setOnClickListener(null);
v.setOnLongClickListener(null);
v.setLongClickable(false);
TextView tt = (TextView) v.findViewById(R.id.category);
tt.setText(item.getName());
} else if (cat.getClass().equals(OrderItem.class)) {
v = vi.inflate(R.layout.menu, null);
OrderItem orderItem = (OrderItem)cat;
Item item …Run Code Online (Sandbox Code Playgroud)