0
我正在做一個listView,我想膨脹三種不同的佈局。每行的例子都有一個條件:如果x ==「F」,那麼R.layout.row1應該膨脹,如果x ==「t」R.layout.row2應該膨脹,我有三行。使用我如何製作三種不同行佈局的ListView?
@Override
public int getViewTypeCount() {
return 3;
}
//
@Override
public int getItemViewType(int position) {
objBean = items.get(position);
if (objBean.gettype() == "I") {
return layout2;
} else if (objBean.gettype() == "F") {
return layout1;
} else {
return layout3;
}
return i;
}
和getview方法
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
objBean = items.get(position);
int type = getItemViewType(position);
String t = objBean.gettype();
// if(i == 0){
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (type == layout2) {
view = inflater.inflate(R.layout.row1, null);
} else if (type == layout1) {
view = inflater.inflate(R.layout.list, null);
} else{
view = inflater.inflate(R.layout.twitter, null);
}
holder = new ViewHolder();
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
其中
int layout1 = 0;
int layout2 = 1;
int layout3 = 2;
看到這個問題1. http://stackoverflow.com/questions/11645160/listview -rows-with-different-layouts 2. http://www.vogella.com/articles/AndroidListView/article.html – SilentKiller
什麼是問題? –
它只返回一個視圖,即layout1 – Saad