【发布时间】:2011-08-05 14:53:37
【问题描述】:
我有一个内部类,它扩展了 ArrayAdapter 以自定义 ListView。我想将这个内部类分解成一个单独的文件,以便其他类可以使用它,但 getLayoutInflater() 会遇到一些问题。
基本上,我的 getView() 方法不知道 getLayoutInflater() 是什么,即使我正在扩展 ArrayAdapter。任何人都知道如何使它正常工作?
谢谢!
public class myDynAdap extends ArrayAdapter<String>
{
String [] list;
public myDynAdap (Context context, int textViewResourceId, String [] objects)
{
super (context, textViewResourceId, objects);
mCtx = context;
list = objects;
}
@Override
public View getView (int position, View convertView, ViewGroup parent)
{
View row = convertView;
if (row == null)
{
LayoutInflater inflater = getLayoutInflater (); // <--- "The method getLayoutInflater() is undefined for the type myDynAdap"
row = inflater.inflate (R.layout.main_listitem, parent, false);
}
TextView tv1 = (TextView) row.findViewById (R.id.tv_item);
tv1.setBackgroundColor (Color.BLUE);
// change background of 0th list element only
if (position == 0)
tv1.setBackgroundColor (Color.CYAN);
return row;
}
}
【问题讨论】:
标签: android android-arrayadapter