开发者

Android: CustomListAdapter

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 t开发者_JAVA百科ried 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..


I cannot understand what I am doing wrong!

Did you implement onCreateContextMenu()?

Is it possible to display a textview above the listview?

Yes.

I tried it by adding the code for textview above the listview. But then, only the textview gets displayed.

See this sample project from one of my books for a TextView above a ListView.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜