我正在做一個應用程序,用戶可以選擇一個設計,然後在下一頁輸入他們的詳細信息。現在,用戶可以選擇多種設計,然後根據他們選擇的設計,該設計將顯示爲下一頁中的預覽。爲了避免爲每個設計分配一個java類,我希望有一個類可以更改預覽圖像,具體取決於用戶選擇的設計。更改ImageView在不同的活動依賴於按鈕按
目前,我可以更改第二個活動中顯示的圖像,但無法將圖像更改爲用戶選擇的特定設計。
This is what the page looks like where the user chooses their design (named SelectDesign.java)
This is what the preview page looks like (named GarmentEntry.java)
下面是他們選擇設計該活動的代碼 - SelectDesign.java(我只是爲了簡單起見前三設計 - 它們都具有相同的基本輪廓)
package com.example.joe.printedclothing;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
public class SelectDesign extends AppCompatActivity {
private static Button HenCockButton, CocktailHenButton, ValueHenButton, XAngelsButton, AlcDisposal, LastNightOfFreedom, BeaverPatrol, Paraletic, FellasOnTour, ValueStag, Wolfpack, PhotoStagHen;
ImageView imagePreviewButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_design);
HenCockButton = (Button) findViewById(R.id.hencocksthumbB);
HenCockButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent henCockIntent = new Intent(SelectDesign.this, GarmentEntry.class);
henCockIntent.putExtra("hen cock parameter", R.drawable.onehenthreechicks);
startActivity(henCockIntent);
}
});
CocktailHenButton = (Button) findViewById(R.id.cocktailhenthumb);
CocktailHenButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cocktailHenIntent = new Intent(SelectDesign.this, GarmentEntry.class);
cocktailHenIntent.putExtra("cocktail hen parameter", R.drawable.cocktailhen);
startActivity(cocktailHenIntent);
}
});
ValueHenButton = (Button) findViewById(R.id.valuehenthumb);
ValueHenButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent valueHenIntent = new Intent(SelectDesign.this, GarmentEntry.class);
valueHenIntent.putExtra("Value Hen parameter", R.drawable.valuehen);
startActivity(valueHenIntent);
}
});
下面是他們進入他們的詳細資料,並有一個預覽活動的代碼 - GarmentEntry.java(不包括的東西像紡紗和按鈕的代碼)
package com.example.joe.printedclothing;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
public class GarmentEntry extends AppCompatActivity {
Spinner tcshenspinner, backprintoptionsspinner, tcbackhenspinner, cosspinner, ppspinner;
ArrayAdapter<CharSequence> tcshenspinneradapter, backprintoptionsspinneradapter, tcbackhenspinneradapter, cosspinneradapter, ppspinneradapter;
Button nextButton1;
public static ImageView imagePreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.garment_entry);
imagePreview = (ImageView) findViewById(R.id.imagePreview);
// Hen cocks
imagePreview.setImageResource(getIntent().getIntExtra("hen cock parameter", R.drawable.onehenthreechicks));
// Cocktail hen
imagePreview.setImageResource(getIntent().getIntExtra("cocktail hen parameter", R.drawable.cocktailhen));
// Value hen
imagePreview.setImageResource(getIntent().getIntExtra("Value Hen parameter", R.drawable.valuehen));
現在,我明白了爲什麼只有一個圖像被傳遞到下一個活動。代碼被順序讀取,所以它讀取最後一個值(我認爲我在這裏是正確的)。但我不知道如何使圖像更改取決於用戶選擇的圖像。任何幫助將不勝感激!