android - How to use R to select a ListView when using it with ListActivity -
i have code:
public class myactivity extends listactivity implements onclicklistener { private arraylist<string> listitems = new arraylist<string>(); arrayadapter<string> adapter; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.setadapter(); this.bindbuttons(); } private void setadapter() { setcontentview(r.layout.siteactivity); adapter=new arrayadapter<string>(this, r.layout.siteitem, listitems); setlistadapter(adapter); } private void bindbuttons() { findviewbyid(r.id.buttonprevious).setonclicklistener(this); findviewbyid(r.id.buttonnext).setonclicklistener(this); } // ... }
with layout:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/siteactivity"> <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/navigation"> <button android:text="<=" android:textsize="12dp" android:id="@+id/buttonprevious" android:layout_width="wrap_content" android:layout_height="wrap_content"> </button> <button android:text="=>" android:textsize="12dp" android:id="@+id/buttonnext" android:layout_width="wrap_content" android:layout_height="wrap_content"> </button> </linearlayout> <listview android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/navigation" android:layout_above="@+id/transport_selection" /> </relativelayout>
note android:id="@android:id/list"
of listview. if replace android:id="@+id/list"
, activity force closes, because "content must have listview id attribute 'android.r.id.list'", expected behaviour, think.
now, want add context menu items of listview. tryed registerforcontextmenu(findviewbyid(r.id.list));
, doesn't work, because of android:id
.
then, how can add context menu?
regards,
as using listactivity, can use following code list view in code:
listview mylistview=getlistview ();
Comments
Post a Comment