我在customlistadapter中创建image_details。在此适配器期间,为每个项设置变量int Answer
。通过调试器我看到我在需要它的地方有数据,但我不知道如何访问它:
调试器图像:
在这里你可以看到我有6个问题,每个问题都有变量SaveButton = ((Button) rootView.findViewById(R.id.Save));
SaveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Object c = image_details.get(1);
}
});
(打开一个设置为0)。当我按保存时,我想要求每个项目的答案(全部6):
onClick
我应该在QuestionItem
中放置什么来检索此数据?
这是我的public class QuestionItem {
private String Question;
private String Answer1;
private String Answer2;
private String Answer3;
private String Answer4;
private int Answer;
private String[] Answers;
public String getQuestion() {
return Question;
}
public void setQuestion(String Question) {
this.Question = Question;
}
public String Getanswer1() {
return Answer1;
}
public void setAnswer1(String Answer1) {
this.Answer1 = Answer1;
}
public String Getanswer2() {
return Answer2;
}
public void setAnswer2(String Answer2) {
this.Answer2 = Answer2;
}
public String Getanswer3() {
return Answer3;
}
public void setAnswer3(String Answer3) {
this.Answer3 = Answer3;
}
public String Getanswer4() {
return Answer4;
}
public void setAnswer4(String Answer4) {
this.Answer4 = Answer4;
}
public int GetAnswer() {
return Answer;
}
public void setAnswer(int Answer) {
this.Answer = Answer;
}
}
课程:
{{1}}
答案 0 :(得分:1)
使用实例变量。下面是一个例子
public class Employee{
// this instance variable is visible for any child class.
public String name;
// salary variable is visible in Employee class only.
private double salary;
// The name variable is assigned in the constructor.
public Employee (String empName){
name = empName;
}
// The salary variable is assigned a value.
public void setSalary(double empSal){
salary = empSal;
}
// This method prints the employee details.
public void printEmp(){
System.out.println("name : " + name );
System.out.println("salary :" + salary);
}
public static void main(String args[]){
Employee empOne = new Employee("Ransika");
empOne.setSalary(1000);
empOne.printEmp();
}
}