android - ListActivity: Add reaction when pressing on List Item -
i'm starting out java/android studio , wrote following listactivity:
public class transmitchaptersel extends listactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); string[] chapters = {"chapter 1", "chapter 2", "chapter 3"}; arrayadapter<string> adapter = new arrayadapter<string>(getlistview().getcontext(), android.r.layout.simple_list_item_1, chapters); getlistview().setadapter(adapter); } }
but don't know how can produce reaction when click/touch/hold 1 of list items.
what want produce this:
pseudocode:
if(actionevent e == chapter1pressed){ //do stuff }
or:
pseudocode:
while(actionevent e == chapter1helddown){ //do stuff }
if need know when item clicked can use onitemclicklistener
list view.
getlistview().setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view,int position, long id) { //do stuff }});
if need know when it's held down you're going have create own list adapter, , set touch listener on row. pretty tutorial on creating list adapters. http://www.vogella.com/tutorials/androidlistview/article.html#adapterown
Comments
Post a Comment