evenmonkeys
Newbie
I'm still extremely new to programming for Android. Please keep that in mind when answering. Thank you. 
I am making a comic application. It shows an image with a previous page button and a next page button. I figured out how to make a button that changes the image.. but I'm having some problems.
I can only get one button to work. Also, when you change the image, you also have to change the page you're on. Doing so changes what the button needs to do.
Below is what I have. The idea is that clicking the "next page" button will change the image and change the int to a new value. Click the same button again and it changes the image and the int to a new value again. But if you click the "previous page" button, it just ignores it altogether. And that's because it's a different integer. And I can't figure out how to change two ints in one case.
I hate to ask someone to create the code for me.. but people have been "directing" me toward the right idea.. and I don't get it. So yeah.. I need someone to give me an example so I can break it down to see how it works.
I guess.. I want an image.. with a back and forward button. And in the background.. a single integer. And when you click the back button, it subtracts 1. Click the forward and it adds one. And the image shown corresponds to the integer. Or even just swiping left or right to go back or forth would be awesome too! Like this example (just click an example.. then an image.. and you'll see the swiping).
Any help would be greatly appreciated. -_-

I am making a comic application. It shows an image with a previous page button and a next page button. I figured out how to make a button that changes the image.. but I'm having some problems.
I can only get one button to work. Also, when you change the image, you also have to change the page you're on. Doing so changes what the button needs to do.
Below is what I have. The idea is that clicking the "next page" button will change the image and change the int to a new value. Click the same button again and it changes the image and the int to a new value again. But if you click the "previous page" button, it just ignores it altogether. And that's because it's a different integer. And I can't figure out how to change two ints in one case.
Code:
public class ComicsActivity extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
android.view.MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_exit:
finish();
}
return true;
}
Button button1;
Button button2;
ImageView image;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
addListenerOnButton();
}
private void addListenerOnButton() {
image = (ImageView) findViewById(R.id.worksheets_100);
/*
final Button back_int = (Button)findViewById(R.id.previouspage);
back_int.setTag(0);
button1 = (Button) findViewById(R.id.previouspage);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View back) {
final int back_int =(Integer) back.getTag();
if(back_int == 0) {
Context context = getApplicationContext();
CharSequence text = "No prior pages.";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
} else if(back_int == 1) {
image.setImageResource(R.drawable.worksheets_100);
back.setTag(2);
} else if(back_int == 2) {
image.setImageResource(R.drawable.worksheets_101);
back.setTag(3);
} else if(back_int == 3) {
image.setImageResource(R.drawable.worksheets_102);
back.setTag(4);
} else if(back_int == 4) {
image.setImageResource(R.drawable.worksheets_103);
back.setTag(5);
} else if(back_int == 5) {
image.setImageResource(R.drawable.worksheets_104);
back.setTag(6);
} else if(back_int == 6) {
image.setImageResource(R.drawable.worksheets_105);
back.setTag(7);
} else if(back_int == 7) {
image.setImageResource(R.drawable.worksheets_106);
back.setTag(8);
} else if(back_int == 8) {
image.setImageResource(R.drawable.worksheets_107);
back.setTag(9);
} else if(back_int == 9) {
image.setImageResource(R.drawable.worksheets_108);
back.setTag(10);
} else if(back_int == 10) {
image.setImageResource(R.drawable.worksheets_109);
back.setTag(11);
} else if(back_int == 11) {
image.setImageResource(R.drawable.worksheets_110);
back.setTag(12);
} else if(back_int == 12) {
image.setImageResource(R.drawable.worksheets_111);
back.setTag(13);
} else if(back_int == 13) {
image.setImageResource(R.drawable.worksheets_112);
back.setTag(14);
} else if(back_int == 14) {
image.setImageResource(R.drawable.worksheets_113);
back.setTag(15);
} else if(back_int == 15) {
image.setImageResource(R.drawable.worksheets_114);
back.setTag(16);
} else if(back_int == 16) {
image.setImageResource(R.drawable.worksheets_115);
back.setTag(17);
}
}
});
*/
final Button page_int = (Button)findViewById(R.id.nextpage);
page_int.setTag(0);
button2 = (Button) findViewById(R.id.nextpage);
button2.setOnClickListener(new OnClickListener() {
public void onClick(View page) {
final int page_int =(Integer) page.getTag();
if(page_int == 0) {
image.setImageResource(R.drawable.worksheets_101);
page.setTag(1);
} else if(page_int == 1) {
image.setImageResource(R.drawable.worksheets_102);
page.setTag(2);
} else if(page_int == 2) {
image.setImageResource(R.drawable.worksheets_103);
page.setTag(3);
} else if(page_int == 3) {
image.setImageResource(R.drawable.worksheets_104);
page.setTag(4);
} else if(page_int == 4) {
image.setImageResource(R.drawable.worksheets_105);
page.setTag(5);
} else if(page_int == 5) {
image.setImageResource(R.drawable.worksheets_106);
page.setTag(6);
} else if(page_int == 6) {
image.setImageResource(R.drawable.worksheets_107);
page.setTag(7);
} else if(page_int == 7) {
image.setImageResource(R.drawable.worksheets_108);
page.setTag(8);
} else if(page_int == 8) {
image.setImageResource(R.drawable.worksheets_109);
page.setTag(9);
} else if(page_int == 9) {
image.setImageResource(R.drawable.worksheets_110);
page.setTag(10);
} else if(page_int == 10) {
image.setImageResource(R.drawable.worksheets_111);
page.setTag(11);
} else if(page_int == 11) {
image.setImageResource(R.drawable.worksheets_112);
page.setTag(12);
} else if(page_int == 12) {
image.setImageResource(R.drawable.worksheets_113);
page.setTag(13);
} else if(page_int == 13) {
image.setImageResource(R.drawable.worksheets_114);
page.setTag(14);
} else if(page_int == 14) {
image.setImageResource(R.drawable.worksheets_115);
page.setTag(15);
} else if(page_int == 15) {
image.setImageResource(R.drawable.worksheets_116);
page.setTag(16);
} else if(page_int == 16) {
Context context = getApplicationContext();
CharSequence text = "The End";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
});
}
}
I guess.. I want an image.. with a back and forward button. And in the background.. a single integer. And when you click the back button, it subtracts 1. Click the forward and it adds one. And the image shown corresponds to the integer. Or even just swiping left or right to go back or forth would be awesome too! Like this example (just click an example.. then an image.. and you'll see the swiping).
Any help would be greatly appreciated. -_-