是否有可能創建一個ListView,其中列表中的每一行都是唯一的佈局(您不知道佈局結構,因爲它是在運行時動態生成的)?Android:具有唯一行的ListView
編輯:
因此,我行可能是這樣的:
- [---] [-------] [ - ] [----- -----------]
- [-------] [----------] [------------- ]
- [ - ] [-------] [----------] [----------]
等等(一個ssume右側對齊)。每個人最有可能是獨一無二的。我知道ListView假定回收視圖的結構與每個行項目相同,但是有什麼方法可以將Listview用於動態創建的行嗎?
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.guide_program_row, null);
holder = new ViewHolder();
holder.programRow = (LinearLayout)convertView.findViewById(R.id.program_row);
Log.i(TAG, "New Row; position = " + position);
}
else {
Log.i(TAG, "Cached Row; position = " + position);
holder = (ViewHolder)convertView.getTag();
}
holder.programRow.addView(buildRow(programLengths));
return convertView;
}
static class ViewHolder {
LinearLayout programRow;
}
public LinearLayout buildRow(int [] programLengthRow) {
Display display = getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
int programCellWidth = screenWidth/5;
int programCellHeight = (int)(screenHeight * 0.6/9);
int timeLeft = maxTimes;
LinearLayout programRow = new LinearLayout(getApplicationContext());
for (int j = 0; j < maxTimes; j++) {
if (timeLeft <= 0)
break;
Movie movie = movieList.get(j);
LinearLayout programCell = (LinearLayout)mInflater.inflate(R.layout.guide_program_cell, null);
TextView programText = (TextView)programCell.findViewById(R.id.program_cell_text);
if (programLengthRow[j] > timeLeft) {
programCell.setLayoutParams(new LinearLayout.LayoutParams(programCellWidth * timeLeft, programCellHeight));
programText.setText(movie.title + " >>");
}
else {
programCell.setLayoutParams(new LinearLayout.LayoutParams(programCellWidth * programLengthRow[j], programCellHeight));
programText.setText(movie.title);
}
timeLeft = timeLeft - programLengthRow[j];
programRow.addView(programCell);
}
return programRow;
}
我會回答是的,你可以,但你卡在哪裏?你有一個listadapter提供你的列表視圖與行視圖? – njzk2