嗨,我是新來創建一個自定義適配器,我目前在大學。 我很難找出爲什麼我的新Bmi(Bmi bmi)在我的基礎類方法中從未被使用過。這裏的代碼請看看你能看到我做錯了什麼?非常感謝新來創建一個自定義適配器
public class BaseActivity extends AppCompatActivity
{
public int height;
public int weight;
public int bmiTotals = 0;
public static List<Bmi> bmis = new ArrayList<Bmi>();
public boolean newBmi(Bmi bmi) {
boolean nonValue = (height * weight) < 0;
if(!nonValue) {
if (height > 0 && weight > 0) {
int bm = height/100;
int bn = weight;
bmiTotals = bn/(bm * bm);
bmis.add(bmi);
bmiTotals = bmi.bmiTotal;
} else {
Toast.makeText(this, "No values entered!", Toast.LENGTH_SHORT).show();
}
}
return nonValue;
}
///////////////////////////////////////This is in a separate class called Bmi
public class Bmi {
public int height;
public int weight;
public int bmiTotal;
public Bmi (int height, int weight, int bmiTotal)
{
this.height = height;
this.weight = weight;
this.bmiTotal = bmiTotal;
}
}
它看起來像什麼事也沒叫你'newBmi()'方法。我認爲你想要像'bmis.add(newBmi());'在某處。我想也是,從來沒有電話給'新Bmi(176,176,200)'或是什麼。所以,你永遠不會創建Bmi對象,它們也不會被放入列表中。 – Jameson
非常感謝您的幫助 – IrishProgrammer