所以我想根据用户点击的图像按钮开始一项活动 目前我有这样的事情:
private void LoadDrawer() {
// TODO Auto-generated method stub
ImageButton Home, Icon, Ranking, History;
Home = (ImageButton) findViewById(R.id.ibHome);
Icon = (ImageButton) findViewById(R.id.ibIcon);
Ranking = (ImageButton) findViewById(R.id.ibRanking);
History = (ImageButton) findViewById(R.id.ibHistory);
Home.setOnClickListener(this);
Icon.setOnClickListener(this);
Ranking.setOnClickListener(this);
History.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.ibHome:
ClassLoader App2;
Intent intent2 = new Intent(this, App2.class);
break;
case R.id.ibIcon:
Intent intent1 = new Intent(this, App1.class);
break;
case R.id.ibRanking:
Intent intent4 = new Intent(this, App4.class);
break;
case R.id.ibHistory:
Intent intent5 = new Intent(this, App5.class);
break;
}
}
现在您在那里看到意图的原因是因为我尝试过使用意图来启动其他活动,但无济于事......
现在我以这种方式检索意图:
Intent intent[number] = getIntent();
String message = intent[number].getAction();
它实际上并没有在那里保持数字,它只是我所拥有的,例如我在这里有2,因为这是来自app2
答案 0 :(得分:3)
我不太明白你的问题是什么。应该就这么简单......
@Override
public void onClick(View v) {
Intent i = null;
switch (v.getId()) {
case R.id.ibHome:
i = new Intent(this, App2.class);
break;
case R.id.ibIcon:
i = new Intent(this, App1.class);
break;
case R.id.ibRanking:
i = new Intent(this, App4.class);
break;
case R.id.ibHistory:
i = new Intent(this, App5.class);
break;
}
if (i != null)
startActivity(i);
}
答案 1 :(得分:-1)
你也可以使用这样的东西:
Home= (ImageButton) findViewById(R.id.ibHome);
Home.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(MainActivity.this, App2.class);
startActivity(i);
}
});
Icon= (ImageButton) findViewById(R.id.ibIcon);
Icon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(MainActivity.this, App1.class);
startActivity(i);
}
});