comboboxアイテムのインデックスを配列に格納しました。今私はそれを取得しているとき、私は同じインデックスを取得しています。java:arrayListに格納されたインデックスの関連値を取得する方法
私はそのインデックスの関連Valueを表示したいと考えています。
ここに私のコードです。
これは、配列にインデックスを追加するための関数です。
public void addData() {
// Retrive the text field values and combo box selected index and store them in variable
int roomIndex = roomTypeCombo.getSelectedIndex();
int mealIndex = mealCombo.getSelectedIndex();
Int daysIndex = daysCombo.getSelectedIndex();
//create the object of Customer class and pass the parameters
Customer c = new Customer(roomIndex, mealIndex, daysIndex);
myList.add(c); // add data into array list
} // end of function
そうしないのはなぜこれがコンボボックスの値を示すことはあなたの条件である場合はArrayListの
public void showAll() {
String displayRecords = ""; // empty string
// retrieve all stored records in array list and store in variable
for (int i = 0; i < myList.size(); i++) {
displayRecords = displayRecords + myList.get(i) + "\n";
}
display.setText(displayRecords);
} // end of function
ようこそスタックオーバーフロー!あなたの質問の下で「編集」リンクを使用して、より読みやすいようにフォーマットしてください。編集エリアの下にプレビューが表示されるので、質問を投稿するときに表示される内容や、テキストエリアの右側に書式設定情報(「書式設定方法」)とリンクそれ(** [?] **ボタンが物事をキックオフする)。 –
CustomerクラスでtoString()メソッドはどのように見えますか? – Churk
また、ベストプラクティスのために、 'String displayRecords'と' displayRecords + = xxx'を使用しないでください。cuz stringは不変オブジェクトです。StringBufferを使用してください。 – Churk