0
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;
}

I am passing two different layouts at runtime, how can i identify which layout i am passing in the getView() method. I am using ArrayAdapter.

4

2 回答 2

1

您可以使用布局 ID 来检查通过了哪个布局

if(passedresourceID == R.layout.layout1)
{
    //do something
}
else if(passedresourceID == R.layout.layout2)
{
    //do something
}
于 2013-04-20T14:17:10.370 回答
1

您应该能够检查传递给的父 IDgetView()

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);
于 2013-04-20T14:20:20.307 回答