【发布时间】:2013-12-09 17:34:01
【问题描述】:
我知道stackoverflow上已经贴了很多类似的问题,所以请不要以为我没有搜索过高低。我认为我的问题只是来自现在完全理解 listViews 和列表项的生命周期。我有一个列表视图,可以包含两种类型的消息,出站或入站。最初,我的 listView 会根据消息的类型(出站与入站)使用不同的背景颜色,并且它完美地工作。现在我的应用程序不需要为列表项设置不同的背景,但它实际上需要为不同的列表项设置不同的布局。
这是我的适配器的剪辑。
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
SoapBoxMessage thisMessage = messages.get(position);
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (thisMessage.isOutbound()) {
v = inflater.inflate(R.layout.outbound_row, null);
} else {
v = inflater.inflate(R.layout.inbound_row, null);
}
}
【问题讨论】:
标签: java android listview android-listview