这是我的 World_Heritage 活动代码,请帮帮我。它有三个按钮(下一个、上一个、第一个)和一个图像视图。如果我单击下一个按钮,图像应该会改变
公共类 World_Heritage 扩展 Activity 实现 View.OnClickListener {
ImageView draw = (ImageView)findViewById(R.id.imageView1);
int a=0;
Button butnnext;
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.worldheritage);
Button butnpre = (Button)findViewById(R.id.buttonprevious);
butnpre.setOnClickListener(this);
Button butnfir = (Button)findViewById(R.id.buttonfirst);
butnfir.setOnClickListener(this);
butnnext = (Button)findViewById(R.id.buttonnext);
butnnext.setOnClickListener(this);
// TODO Auto-generated method stub
}
public void onClick(View v)
{
switch(v.getId())
{
case R.id.buttonfirst:
draw.setImageResource(R.drawable.agra_fort);
a=0;
break;
case R.id.buttonnext:
if(a==0)
{
draw.setImageResource(R.drawable.ajantha_caves);
a=1;
}
else if(a==1)
{
draw.setImageResource(R.drawable.bhimbetka);
a=2;
}
else if(a==2)
{
draw.setImageResource(R.drawable.champaner);
a=3;
}
else if(a==3)
{
draw.setImageResource(R.drawable.chttrabadhi);
a=4;
}
else if(a==4)
{
draw.setImageResource(R.drawable.church);
a=5;
}
else if(a==5)
{
draw.setImageResource(R.drawable.elephanta);
a=6;
}
else if(a==6)
{
draw.setImageResource(R.drawable.ellora_caves);
draw.setClickable(false);
}
break;
case R.id.buttonprevious:
a--;
butnnext.performClick();
break;
}
}
}