我正在为我 2 岁的孩子设计一个简单的数字抽认卡屏幕。布局很简单,有一个标题标题,一个图像(抽认卡说 1)。当我单击图像(或屏幕上的任何位置)时,它应该转到下一个图像(抽认卡 2),依此类推,直到 10 点。我的问题 - 我需要定义 10 个布局吗?10个活动?android 编码新手 - 感谢任何帮助。
public void numberClick(View v) {
ImageView portrait = (ImageView) findViewById(R.id.numberImage);
switch(v.getId()){
case R.drawable.numberone:
portrait.setImageResource(R.drawable.numbertwo);
case R.drawable.numbertwo:
portrait.setImageResource(R.drawable.numberthree);
}
更新代码
public class numberActivity extends Activity {
ImageView portrait;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.number);
portrait = (ImageView) findViewById(R.id.numberImage);
}
public void numberClick(View v) {
switch(v.getId()){
case R.drawable.numberone:
portrait.setImageResource(R.drawable.numbertwo);
break;
case R.drawable.numbertwo:
portrait.setImageResource(R.drawable.numberthree);
break;
}
}
}
但结果仍然不存在 - 图像不切换。
使用监听器更新代码
public class numberActivity extends Activity {
ImageView portrait;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.number);
portrait = (ImageView) findViewById(R.id.numberImage);
portrait.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
switch(v.getId()){
case R.drawable.numberone:
portrait.setImageResource(R.drawable.numbertwo);
break;
case R.drawable.numbertwo:
portrait.setImageResource(R.drawable.numberthree);
break;
}
}});
}}