我正在尝试为标题导航创建按钮侦听器,以便侦听器可以位于某个地方。
我希望做出这样的方法:
public void set_nav_listeners ( )
{
Button planBusiness = (Button)findViewById(R.id.home_header);
Button questions_header = (Button)findViewById(R.id.questions_header);
learn_header.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent(ProblemioActivity.this, LearnActivity.class);
ProblemioActivity.this.startActivity(myIntent);
}
});
questions_header.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent(ProblemioActivity.this, QuestionsActivity.class);
ProblemioActivity.this.startActivity(myIntent);
}
});
}
并在那里传递参数,使其适用于每个活动。所以像这样的调用会起作用:
public class RandomActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// For checking if the person is logged in.
set_nav_listeners ( ---> What parameters can I pass so it would work? <---- );
...
那可能吗?我该如何解决这个问题?
谢谢!