views:

112

answers:

1

Hi,

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..

+1  A: 

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.

CommonsWare
Yes, I implemented onCreateContextMenu(). Is there some-other way to show a menu for items in the list?I've edited the 3rd question to be more clear..
primalpop
"Is there some-other way to show a menu for items in the list?" -- no your approach is correct. See here for a sample project implementing a context menu on a ListView: http://github.com/commonsguy/cw-android/tree/master/Database/Constants/ With respect to your question #3, that might be a `PopupWindow`.
CommonsWare
How do I implement a PopupWindow? Is it possible to get input in a PopupWindow?
primalpop