本文介绍了不能宣布ViewHolder为静态内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我使用的是列表视图,并通过扩展阵列adapter.However,扩展接口里面,我无法申报viewholder为静态内部类的标准定制相关的阵列适配器。 Eclipse中一直给错误的静态类型只能在静态或顶层类型的声明。这里是code:

In my application, I am using a listview and have customized the associated array adapter by extending the standard the array adapter.However,inside the extended adapter, I am unable to declare the viewholder as a static inner class. Eclipse keeps giving the error that "static types can only be declared in static or top level types". Here is the code:

public class IconicAdapter extends ArrayAdapter<String>
{
    public static class ViewHolder
    {
        public TextView text;
        public ImageView image;
    }

    public IconicAdapter() {
        super(MainActivity.this,R.layout.row,values);
        // TODO Auto-generated constructor stub
    }

    public View getView(int position,View convertView, ViewGroup parent)
    {
        View row = convertView;
        if(row == null)
        {
            LayoutInflater inflater = getLayoutInflater();
            row = inflater.inflate(R.layout.row, parent,false);
        }
        TextView label =(TextView)row.findViewById(R.id.label);
        label.setText(values[position]);
        ImageView icon = (ImageView)row.findViewById(R.id.icon);
        icon.setImageResource(R.drawable.ok);

        return (row);
    }
}

任何建议?

推荐答案

如果 IconicAdapter 是一个内部类,你将不能够在声明一个内部静态类它,除非 IconicAdapter 将被声明为静态类。

If IconicAdapter is an inner class, you won't be able to declare an inner static class within it unless IconicAdapter WILL be declared as a static class.

这篇关于不能宣布ViewHolder为静态内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 14:26