Starting an activity from a view in android?
Is there a way to start an activity from a view? I have this nice view that renders these menu buttons and when they click a particular button (Trapped in an onTouch event) I want to start the "clicked" activity.
It seems that there from my view startActivity method is uncallable. So that leads me to believe that there is no way to do this, in which case I guess I am asking, what do I do here when I want this menu to have a view that animates drawables and can get touches to know what "button" was pressed to know what activity to start?
I have been searching and nothing seems to fit what I am looking for. I suspect since I cannot find it that it probably breaks convention in some way and in which case, what is the proper wa开发者_StackOverflow社区y to do this?
I have another Activity that starts this cool scrolling tile map view. When the user clicks on a specific tile I would like to load up an entirely different view (maybe even activity not sure which I need) based on the tileID clicked. This new View or activity would show all the items in the cell that was clicked (imagine the map with cells , each cell has stuff in it. When the user clicks on the cell then a new view happens that shows all this stuff as cool drawables, like it "zoomed in" on the cell).
I would think I need the same thing, when the user is inside my scrolling map view and they push down then up I get what cell they clicked on and use that to initialize the activity that will launch showing the zoomed in state of things (via drawables using a new kind of view i suspect)
Is there a way to start an activity from a view?
Arguably, the View
should tell the Activity that hosts it to start an activity, via a registered callback method. I am not a fan of the code organization you have described here (but, admittedly, based solely on the description).
However, if you really want to have the View
start the activity, have the View
call getContext().startActivity()
.
you do start an activity using the startActivity.
// first create the intent
Intent intent = new Intent ( this, ClickedActivity.class );
// start the activity
this.startActivity( intent );
精彩评论