1
我有一個GridView。它總是兩列。Android GridView,回收兩個不同的單元格?
對於僅位於頂部的前兩個單元格,我有不同的單元格。
在Apdater我做到這一點...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (position<2) {
// just return a new header cell - no need to try to be efficient,
// there are only ever two of the header cells
convertView = LayoutInflater.from(c).inflate(R.layout.cell_header, null);
return convertView;
// you're completely done
}
// from here, we want only a normal cell...
if (convertView == null) {
// just make a new one
convertView = LayoutInflater.from(c).inflate(R.layout.d.cell_normal, null);
}
// if you get to here, there's a chance it's giving us a header cell to recycle,
// if so get rid of it
int id = convertView.getId();
if (id == R.id.id_cell_header) {
Log.d("DEV", "We got a header cell in recycling - dump it");
convertView = LayoutInflater.from(c).inflate(R.layout.cell_normal, null);
}
... populate the normal cell in the usual way
return convertView;
}
這個偉大的工程。注意我只是不回收標題單元格。沒有問題,因爲只有兩個。
但是如果你想要一個GridView和兩個完全不同的單元格呢? (想象一下GridView與每種類型的說50,所有混合在一起。)
我的意思是,兩者都是相同的大小,但他們是完全不同的,兩個不同的XML文件,完全不同的佈局?
你如何「同時回收」?
這是怎麼回事?
http://stackoverflow.com/a/24717323/115145 – CommonsWare
@CommonsWare - 完全宏偉的,謝謝! – Fattie