2017-07-16 63 views
0

问题的“列表”内的元件的数量更大的计数器大于内“排行榜”的计数器大于

元件这是由一个服务器的响应填充的数量。

公共类ListQuestions延伸活动{

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,但是当我在 “setOnItemClickListener” 检查,这是18

enter image description here

+0

你如何填写此表前检查? –

+0

请再次检查该问题@KillerDeath –

回答

0

你必须把所有的代码,代码在哪里影响问题?

以及您从列表中获取数据,以避免这个问题

if(counter<=list.size-1){ 
//put your code 
} 
+0

这是所有代码的问题所在 –

+0

@juliandavid ok,哪一行导致问题? –

+0

in this line“questions = BusinessLogic.getQuestions(LiveCookie.getInstance()。getToken());” de array是15,但是在这里是de问题:“ResponseQuestionDto selected = questions.get(position);” –