" list"的问题计数器大于
中的元素数量这由服务器的响应填充。
公共类ListQuestions扩展了Activity {
private ListQuestionsAdapter adapter;
ListView listquestion;
List<ResponseQuestionDto> questions = new ArrayList<>();
List<ResponseQuestionDto> questionsSelected;
int positionQuestion;
final Handler mHandler = new Handler();
ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listquestions);
dialog = ProgressDialog.show(this, "",
getString(R.string.progress), true);
Thread thread = new Thread() {
@Override
public void run() {
try {
questions = BusinessLogic.getQuestions(LiveCookie.getInstance().getToken());
mHandler.post(mUpdate);
} catch (Exception e) {
Util.alert(ListQuestions.this, getString(R.string.Error));
}
}
};
thread.start();
}catch (Exception e)
{
Toast.makeText(ListQuestions.this, getString(R.string.Error), Toast.LENGTH_LONG).show();
}
}
final Runnable mUpdate = new Runnable() {
@Override
public void run() {
try {
dialog.dismiss();
questionsSelected = LiveCookie.getInstance().getQuestionsSelected();
positionQuestion = LiveCookie.getInstance().getPositionQuestion();
try {
if(questionsSelected != null)
{
for (int i=0;i<questionsSelected.size();i++) {
if (questionsSelected != null) {
if (questionsSelected.get(i).pregunta != null) {
if (positionQuestion != i) {
for (int e = 0; e < questions.size(); e++) {
if (questions.get(e) != null) {
if (questions.get(e).pregunta.equals(questionsSelected.get(i).pregunta)) {
questions.remove(questions.get(e));
}
}
}
}
}
}
}
}
}catch (Exception e)
{
//Not Used
}
listquestion = (ListView) findViewById(R.id.listquestion);
adapter = new ListQuestionsAdapter(ListQuestions.this,questions);
listquestion.setAdapter(adapter);
listquestion.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter2, View v, int position, long id) {
questionsSelected = LiveCookie.getInstance().getQuestionsSelected();
ResponseQuestionDto selected = questions.get(position);
positionQuestion = LiveCookie.getInstance().getPositionQuestion();
questionsSelected.set(positionQuestion,selected);
LiveCookie.getInstance().setQuestionsSelected(questionsSelected);
ListQuestions.this.finish();
}});
}catch (Exception e)
{
dialog.dismiss();
Toast.makeText(ListQuestions.this, getString(R.string.Error), Toast.LENGTH_LONG).show();
ListQuestions.this.finish();
}
}
};
}
首先列表是14,但是当我在&#34; setOnItemClickListener&#34;中检查它时。这是18岁。
答案 0 :(得分:0)
你必须放置所有代码,代码在哪里影响问题?
你在从列表中获取数据之前检查以避免这个问题
if(counter<=list.size-1){
//put your code
}