Sample code for list/detail Android Activities -
my understanding best practices simple app list , detail activities startactivityforresult()
. let's have app model product (id, name, price)
, productlistactivity
, productdetailactivity
.
i having hard time understanding of activities contain startactivityforresult()
, have setresult()
, result be.
my understanding best practices simple app list , detail >activities startactivityforresult().
i not agree statement.
in opinion, best way set [onlistitemclicklistener](http://developer.android.com/reference/android/app/listactivity.html#onlistitemclick(android.widget.listview, android.view.view, int, long)) in productlistactivity.
when item in list clicked, onlistitemclick() method called, arguments you'll able figure out item in list clicked (for example using second argument - position, position of clicked item in list, starting zero).
once figure out item clicked, you'll create intent , put required extras in there (for example position of clicked item). you'll use intent start productdetailactivity, calling startactivity().
then, in productdetailactivity you'll intent using getintent(), extract extras intent , use them decide display in activity (for example, display text associated position in listview productlistactivity). can extras intent using getextra*() methods.
you use startactivityforresult() if wanted result activity, in example doesn't seem case, want display details. imagine activity did calculations , wanted final value back, using startactivityforresult() 1 of ways of passing value back.
Comments
Post a Comment