這是我World_Heritage活動代碼,請幫我guys.it有三個按鈕(下一個,上,第一)和圖像view.if我點擊下一步按鈕圖像應該改變應用程序意外終止,請稍後再試
公共類World_Heritage擴展活動實現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;
}
}
}
正如我告訴你在你的prev問題中移動findViewById在setContentView之後的onCreate方法 – 2013-03-15 20:05:20
而不是發佈兩個不完整的問題,你應該在你的上一個問題下點擊[edit]來添加這個新的信息。這樣你就會有一個_complete_問題。 – Sam 2013-03-15 20:09:10