是否可以从Android中的Adapter获取ListView的引用而不将其作为构造函数的参数传递?
答案 0 :(得分:12)
绝对有可能。是否应该这样做(是的,有案例)。
// See this method of your adapter
// The parent is the view you are looking for
public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
ListView view = (ListView)parent;
}
答案 1 :(得分:2)
如果您编写自定义适配器(例如CursorAdapter ...),您可以在构造函数中传递listview:
public CursorAdapterStream(Context context,ListView lv) {
super(context, R.layout.row_stream, values);
this.context = context;
this.listview=lv;
}
最后在getView方法中使用listview。
答案 2 :(得分:-5)
不可能,适配器应该知道布局。