2013-12-19 1 views
0

에서 같은 값을 반환한다. 교육 클래스 :데이터베이스에 데이터를 삽입 한 후에 데이터의 개수를 계산하고 난 연수가 텍스트 뷰에서 데이터베이스에 삽입 직후 훈련생의 수를 표시 할 3 훈련생

public void addTrainee(Trainee trainee){  

    // Inserting person details to the database is in separate method 
    trainee.storeToDB(); 

    //Counting the number of participants 
    trainee.countTrainee(this.getId()); 

    // Create the link between the trainee and the training 
    trainee.registerToTraining(this.getId()); 

    // Add the trainee to the attendance list of the current training object 
    this.traineeArrayList.add(trainee);  
} 

연수생 클래스 : 다음은 내 코드입니다

public int countTrainee(int training_id) { 
    DatabaseHelper db = DatabaseHelper.getInstance(); 

    String countQuery = "SELECT * FROM" + DatabaseHelper.TABLE_ATTENDANCE; 
    Cursor cursor = db.select(countQuery); 
    cursor.close(); 
    return cursor.getCount(); 
} 

내 활동 클래스 :

countTrainee = (TextView)findViewById(R.id.traineeCount); 
    countTrainee.setText(trainee.countTrainee(0)); 

내가 완전히 잘못했던 것을 알고있다. 하지만 누군가가이 문제를 해결할 수 있도록 도와 줄 수 있습니까? 이 코드로 무엇을하려고하는지 이해하고 싶습니다.

+0

당신은 가까이하지 커서 다음'getCount()'를 사용할 수 있습니다! –

+0

이 유일한 문제인가요? – user3099195

+0

아니 ... 어디'training_id'이 사용된다? '위해, 무엇'trainee.countTrainee (this.getId())인가? 이 [tag : Android]입니까? –

답변

0

교육 클래스 :

//... 
// Is this result supposed to be used anywhere??? 
trainee.countTrainee(this.getId()); 
//... 

연수생 등급 :

public int countTrainee(int training_id) { 
    int cnt; 
    DatabaseHelper db = DatabaseHelper.getInstance(); 
    Cursor cursor = db.select("SELECT * FROM" + DatabaseHelper.TABLE_ATTENDANCE + " WHERE id="+training_id); 
    cnt=cursor.getCount(); 
    cursor.close(); //Not sure if necessary... 
    return cnt; 
} 
+0

내 문제는 더 나은 솔루션을 찾았습니다. 사실, ArrayList.size()와 같은 목록 배열을 계산하면 해결할 수 있습니다. 그렇지 않니? 왜 나는 데이터베이스를 쿼리 했는가? – user3099195

관련 문제