どうすればこのメソッドを別のクラスで呼び出すことができますか?別のクラスからarraylistメソッドを呼び出す
このメソッド内の配列リストをdatabase helperというクラスから使用して、変数の値を別のクラス(メインメニュー)のこの配列リストと比較する必要があります。
考えられるのは、データベース内のすべての値を取得し、 クラスのメインメニューの値からの変数がクラスデータベースヘルパーの配列リスト内のどこにあるかをチェックすることです。
public ArrayList<Phone> retrieveAllPhones() {
ArrayList<Phone> phoneArrayList
= new ArrayList<>();
// SELECT * FROM student;
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query(Phone.TABLE,
null,// columns
null,// selection
null,// selection args
null,// group by
null,// having
null// order by
);
if (cursor.moveToFirst()) {
do {
Phone phone = new Phone();
phone.setSenderNum(
cursor.getString(cursor.getColumnIndex(Phone.NUM))
);
// assign this name to Student
phone.setMessage(
cursor.getString(cursor.getColumnIndex(Phone.MESSAGE))
);
phone.setGeo(
cursor.getString(cursor.getColumnIndex(Phone.GEO))
);
phoneArrayList.add(phone);
} while (cursor.moveToNext());
}