How to start one activity from Customized View

只谈情不闲聊 提交于 2020-01-02 00:52:24

问题


How to start one activity from another View (another activity View)

For example,

public class CorrectSmoothGloflo extends Activity {
  .......................
  setContentView(new Panel(this));
}


public class Panel extends View {

   //This view class contains some drawable operation
   // Here i want to start another Activity like this

   Intent i=new Intent(CorrectSmoothGloflo.this,Screen.class);
    startActivity(i);   
}

I cant do this operation. Because this is the View, that will not work, because View does not have startActivity(). How to implement this? please give some guidelines.


回答1:


Obtain a Context object and use its startActivity() method:

Context context = getContext();
Intent i = new Intent(context, Screen.class);
context.startActivity(i);



回答2:


Setup an event handler to your "another activity View", and put the activity calling statements in it.




回答3:


Intent i=new Intent(CorrectSmoothGloflo.this,Screen.class); 
startActivity(i); 

as you want to start another activity so u need to pass current context and not the previous like i your example your are mentioned correctsmoothgloflo but it is panel.class

check this is help for u or not...



来源:https://stackoverflow.com/questions/5203019/how-to-start-one-activity-from-customized-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!