2013-04-20 18 views
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; 
} 

我傳遞在運行兩個不同的佈局在運行時Determing佈局,我怎麼能確定我傳遞的getView()方法,它的佈局。我正在使用ArrayAdapterListView中

+0

這裏是完整的代碼父ID? – 2013-04-20 14:12:58

+0

@PankajKumar:你需要哪些代碼,是否希望我將它傳遞給適配器。 – Kevin 2013-04-20 14:13:48

+0

@kevin檢查我的答案 – 2013-04-20 14:18:12

回答

1

您可以使用佈局的ID,以檢查其佈局傳遞

if(passedresourceID == R.layout.layout1) 
{ 
    //do something 
} 
else if(passedresourceID == R.layout.layout2) 
{ 
    //do something 
} 
+0

謝謝sankar ... passedResouceID是一個i​​nt和R.layout.layout1 ...它會工作。 – Kevin 2013-04-20 14:31:41

+1

ya。兩者都是純粹的男人。肯定會起作用。 – 2013-04-20 14:51:41

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); 
+0

謝謝,我沒有得到R.id.layoutToCheck,雖然我在R.Java有一個id – Kevin 2013-04-20 14:32:21

+0

'R.id.YourLayoutName'返回包含在'R.java'中的''id' – codeMagic 2013-04-20 14:34:05

+0

對不起,我有編輯我的帖子。匆忙。 – codeMagic 2013-04-20 14:35:34