Android:具有 2 种布局的自定义适配器
我需要以两种不同的模式显示数据:中视图和大视图。我有一个自定义适配器并将数据显示到列表视图中。当我单击列表视图项目时,我开始一项新活动。通过我的适配器的布局,一切都很完美。现在我尝试在适配器中的两个布局之间切换:我设置为适配器视图模式,然后调用notifyDataSetChanged:
ticketsAdapter.setViewMode(ViewMode.Large);
ticketsAdapter.notifyDataSetChanged();
这也有效,现在我可以看到更多信息(大行布局比中视图具有更多字段)。 问题是,改变对列表视图项目的点击它就不再起作用了。 在我的适配器的 getView 方法中,我做了这样的思考:
LayoutInflater li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
switch (viewMode) {
case Large:
v = li.inflate(R.layout.row_large, null);
break;
case Medium:
v = li.inflate(R.layout.row_medium, null);
break;
default:
v = li.inflate(R.layout.row_medium, null);
break;
}
有人可以帮忙吗?
已修复:
我有一个文本视图:
android:inputType="text"
这导致了问题。 发射机
I need to display my data in 2 different modes: medium and large view. I have a custom adapter and display data into listview. when i click on list view item i start a new activity. With on layout in my adapter everything works perfect. Now i try to switch between two layouts in adapter: i set to the adapter view mode and then call notifyDataSetChanged:
ticketsAdapter.setViewMode(ViewMode.Large);
ticketsAdapter.notifyDataSetChanged();
this also work and now i can see more information (large row layout has more field than medium view).
The problem is that alter this click on listview items it's not working anymore.
In getView method from my adapter i do somethink like this:
LayoutInflater li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
switch (viewMode) {
case Large:
v = li.inflate(R.layout.row_large, null);
break;
case Medium:
v = li.inflate(R.layout.row_medium, null);
break;
default:
v = li.inflate(R.layout.row_medium, null);
break;
}
Can some one help?
Fixed:
I had one textview with:
android:inputType="text"
and this caused the problem.
Tx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论