2017-07-16 35 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);」 –