public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1;
final ImageView image;
button1 = (Button) findViewById(R.id.button1);
image = (ImageView) findViewById(R.id.imageView1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
int j=0;
while(j<=4){
int res=getResources().getIdentifier("d002_p00"+j,"drawable",getPackageName());
image.setBackgroundResource(res);
j = j+1;
}
}
});
image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
}
});
}
}
我有3个问题:
@username
,但它没有用。答案 0 :(得分:0)
回答问题1: What is wrong with this code this code only show 1st and last image? how I can fix it?
将int j
放在onClick之外,将while
更改为if
int j=0;
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(j >= 0 && j <= 4){
int res = getResources().getIdentifier("d002_p00"+j, "drawable", getPackageName());
image.setBackgroundResource(res);
j++;
}
}
});
回答问题2: I don't want to rotate my apps. How I can do that?
See this answer of another stackoverflow question.
回答问题3: How I can mentioned a user in Stack Vverflow? I tried @username but it didn't work.
我自己并不确定,但我认为当只有一个评论者(除了我自己不能)之外,你不能使用@user_name回复评论。但是,如果您想要某人信用,我建议将其个人资料页面放在如下链接中:@user3546792(点击其名称,复制链接,点击SO中的Add Hyperlink
- 按钮并粘贴复制链接。然后将[enter link description here]
更改为[@user_name]
答案 1 :(得分:-1)
问题2:
I don't want to rotate my apps. How I can do that?
你只需在你的Android Manifest中添加它:
android:orientation="portrait"