0
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) {
            }
        });
    }
}

I have 3 questions:

  1. What is wrong with this code this code only show 1st and last image? how I can fix it?
  2. I don't want to rotate my apps. How I can do that?
  3. How I can mentioned a user in Stack Vverflow? I tried @username but it didn't work.
jww
  • 97,681
  • 90
  • 411
  • 885

2 Answers2

0

Answer for question 1: What is wrong with this code this code only show 1st and last image? how I can fix it?

Put the int j outside the onClick and change the while to an 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++;
        }
    }
});

Answer for question 2: I don't want to rotate my apps. How I can do that?

See this answer of another stackoverflow question.

Answer for question 3: How I can mentioned a user in Stack Vverflow? I tried @username but it didn't work.

I don't know for sure myself, but I think you can't use @user_name to reply a comment when there is only one commenter apart from yourself (at least I couldn't). If you want to credit someone however, I would suggest putting their profile-page in a link like so: @user3546792 (Click their name, copy the link, click the Add Hyperlink-button in SO and paste the copied link. Then change [enter link description here] to [@user_name]

Community
  • 1
  • 1
Kevin Cruijssen
  • 9,153
  • 9
  • 61
  • 135
-1

For question 2:

 I don't want to rotate my apps. How I can do that?

Your just add this in your android Manifest:

android:orientation="portrait"
jww
  • 97,681
  • 90
  • 411
  • 885
pavel
  • 1,603
  • 22
  • 19