Android:自定义列表适配器
我已经实现了一个自定义列表视图,看起来像 Twitter 时间线。
adapter = new MyClickableListAdapter(this, R.layout.timeline, mObjectList);
setListAdapter(adapter);
MyClickableListAdapter 的构造函数如下所示
private class MyClickableListAdapter extends ClickableListAdapter{
public MyClickableListAdapter(Context context, int viewId, List objects) {
super(context, viewId, objects);
}
ClickableListAdapter 扩展了 BaseAdapter 并实现了必要的方法。
列表视图的 xml 代码如下
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
:看起来像这样 。
我有 3 个问题
1) 我尝试通过在设置列表适配器后添加行来注册列表视图的上下文菜单
registerforContextMenu(getListView())
;
但长按时不会显示菜单。我无法理解我做错了什么!
2) 是否可以在列表视图上方显示文本视图?我通过在列表视图上方添加文本视图的代码来尝试。但随后,仅显示文本视图。
3) 我在许多 Twitter 客户端中看到,单击选项菜单中的帖子时,会从屏幕顶部弹出一个窗口,仅覆盖所需的内容,并且时间线的其余部分是可见的。在 Android 中如何做到这一点?用于输入消息的窗口,按下发布后消息将传递到启动它的活动。窗口从顶部弹出,仅占据屏幕的四分之一,屏幕的其余部分显示先前活动的内容。
任何帮助将不胜感激..
I have implemented a custom list view which looks like the twitter timeline.
adapter = new MyClickableListAdapter(this, R.layout.timeline, mObjectList);
setListAdapter(adapter);
The constructor for MyClickableListAdapter is as follows
private class MyClickableListAdapter extends ClickableListAdapter{
public MyClickableListAdapter(Context context, int viewId, List objects) {
super(context, viewId, objects);
}
ClickableListAdapter extends BaseAdapter and implements the necessary methods.
The xml code for the list view is as follows
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
This is what it looks like.
I have 3 questions
1) I tried registering a context menu for the list view by adding the line after setting the list adapter
registerforContextMenu(getListView())
;
But on long-click the menu doesnt get displayed. I cannot understand what I am doing wrong!
2) Is it possible to display a textview above the listview? I tried it by adding the code for textview above the listview. But then, only the textview gets displayed.
3) I have seen in many twitter clients that on clicking post in the options menu a window pops up from the top of the screen covering only as much its required and rest of the timeline is visible. How can this be done in Android? A window to enter the message and on pressing post the message is passed to the Activity that started it. The Window pops up from the top and takes only a quarter of the screen, rest of the screen displays the contents of the earlier activity.
Any help would be much appreciated..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你实现了 onCreateContextMenu() 吗?
是的。
请参阅我的一本书中的此示例项目,了解
TextView
位于ListView
上方。在不开始新活动的情况下如何才能做到这一点?
根据你的描述,回答这个问题有点困难。我的猜测是它是通过动画实现的。请参阅我的另一本书中的此示例项目 Twitter 客户端,其中状态更新的字段和按钮可以通过选项菜单选项和动画隐藏和显示。
Did you implement onCreateContextMenu()?
Yes.
See this sample project from one of my books for a
TextView
above aListView
.How can this be done possibly without starting a new activity?
It is a little difficult to answer that given your description. My guess is that it is via an animation. See this sample project from another one of my books for a Twitter client where the field and button for a status update can be hidden and shown via an option menu choice and an animation.