Skip to content Skip to sidebar Skip to footer

How To Use R To Select A Listview When Using It With Listactivity

I have this code: public class MyActivity extends ListActivity implements OnClickListener { private ArrayList listItems = new ArrayList(); Array

Solution 1:

As you are using ListActivity, you can use the following code to get list view in code:

ListView myListView=getListView ();

Solution 2:

Use android.R.id.list instead of R.id.list.

(And by the way, the error message you wrote here turns out to have the answer)

Basically, anything defined in XML as @android:whatever is the same as android.R.whatever in the Java code. Anything that you defined in XML, which will look like @whatever, is the same as R.whatever in Java code.

Final edit: If you're using ListActivity, you are required to have a ListView with the id @android:id/list. Thus, unless you want to add another ListView to your activity, you shouldn't need @+id/list (or R.id.list).

Solution 3:

You need to create an AlertDialog and call the dialog to show inside the listview's onItemLongClick() event. Click here for an example.

Post a Comment for "How To Use R To Select A Listview When Using It With Listactivity"