我从数据库中创建了一个arraylist
public List<String> getAllQuestions(){
List<String> questions = new ArrayList<>();
String query = "SELECT QUESTION FROM QUESTIONS ";
Cursor cursor=db.rawQuery(query, null);
while(cursor.moveToNext()) {
questions.add(cursor.getString(0));
}
cursor.close();
return questions;
}
基本上想在数组列表中显示第一个问题,然后单击我的答案,然后在阵列列表中显示下一个问题……直到所有问题都已显示和回答。
我的代码下面行不通。
Button btnAnswer1, btnAnswer2, btnAnswer3;
LoginDataBaseAdapter LoginDataBaseAdapter;
EditText editNameComplete;
int index = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.message);
LoginDataBaseAdapter = new LoginDataBaseAdapter(CompleteSurveyActivity.this);
LoginDataBaseAdapter.open();
editNameComplete = (EditText) findViewById(R.id.editTextQuestion);
TextView tv = (TextView) findViewById(R.id.questionnn);
This one works when i only want to get the first without using the array method.
//tv.setText(LoginDataBaseAdapter.getQuestion());
however when i try to use the array here, it get a "cannot resolve symbol error.
tv.setText(LoginDataBaseAdapter.getAllQuestions.get(index));
//get refs of buttons
btnAnswer1 = (Button) findViewById(R.id.buttonAnswer1);
btnAnswer1.setText(LoginDataBaseAdapter.getAnswer1());
btnAnswer2 = (Button) findViewById(R.id.buttonAnswer2);
btnAnswer2.setText(LoginDataBaseAdapter.getAnswer2());
btnAnswer3 = (Button) findViewById(R.id.buttonAnswer3);
btnAnswer3.setText(LoginDataBaseAdapter.getAnswer3());
}
我基本上根本不确定如何调用和使用创建arrayList的getAllQuestions方法。
在两个类中导入 java.util.ArrayList;
和 java.util.List;
,它应该起作用。尝试.get(索引(时,您正在使用列表;,所以您必须导入它。