英語でごめんなさい!助けが必要!ボタンクリック後にランダムな画像を表示するプログラムを作成します。ユーザーが画像をクリックした後、各画像の説明を作成するにはどうすればよいですか?
プログラムはランダムな画像を表示し、ユーザーがクリックしたときに新しいウィンドウですべての画像の説明を作成するにはどうすればよいですか?
setOnClickListener
ボタンのメソッドを使用して、必要なことを行うことができます。
final TextView label = (TextView)findViewById(R.id.some_text_label);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
label.setText("Hello, World!");
}
}
Here's a tip.
Use a list or hashmap and create a custom class to hold image and image data. (Changes by a commentor)
Use Math.Random();//Random the id numbers
Stuff to learn: Research button events and view flipper events
Here's an example:
My idea for using weakhashmap and for improvements I recommend saving location instead of the bitmap(wastes memory).
private WeakHashMap<int, Image> whp = new WeakHashMap<Int, Image>
private int position = 0;
public void onCreate{
//Do download information or store images from sd card
//Place it in image class
loop amount of images{
image Image = new image(Bitmap_Image, Image_Description);//load image
whp.add(position, Image);//Note the amount of positions the image is field
position++;
}
//To get bitmap use "whp.get(position).image" <- This code returns a bitmap
setOnClickListener//Create event to listen on clicked image
{
int image_random = new Random().nextInt(position);
String data = whp.get(image_random).note_item;//Image Description
}
}
class image{
Bitmap image;//Actual Image
String note_item;//Image description
public void image(Bitmap intake_image, String intake_description){
this.image = intake_image;
this.note_item = intake_description;
}
}