public AdapterClass(Context a, int resourceID, List < Info > entries) {
super(a, resourceID, entries);
this.layoutResource = resourceID;
}
@
Override
public View getView(int position, View convertView, ViewGroup parent) {
final Object custom = getItem(position);
LinearLayout rowView = null;
if (convertView == null) {
rowView = new LinearLayout(getContext());
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi.inflate(layoutResource, rowView);
} else
rowView = (LinearLayout) convertView;
if (custom != null) {
}
return rowView;
}
我在运行时传递两个不同的布局,如何识别我在getView()
方法中传递的布局。我正在使用ArrayAdapter
。
答案 0 :(得分:1)
您可以使用布局ID来检查传递的布局
if(passedresourceID == R.layout.layout1)
{
//do something
}
else if(passedresourceID == R.layout.layout2)
{
//do something
}
答案 1 :(得分:1)
您应该能够检查传递给getView()
public View getView(int position, View convertView, ViewGroup parent) {
switch (parent.getId()){ //check your ids here
case (R.layout.layoutToCheck):
break;
case (R.layout.otherLayoutToCheck):
...
final Object custom = getItem(position);
LinearLayout rowView = null;
if (convertView == null) {
rowView = new LinearLayout(getContext());
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi.inflate(layoutResource, rowView);