2012-06-21 4 views
0

다른 액티비티간에 데이터를 전달하는 데 사용하는 동일한 프로세스를 사용하여 액티비티와 cursoradapter간에 데이터를 전달할 수 있습니까? 시간이 실행되지 않습니다 생성 오류 내가 어댑터라는 이름 MyAdapterQuestion 및 Basic_database_questionsActivity라는 활동을 컴파일customcursoradapter에서 액티비티로 정수 전달하기

The constructor Intent(MyAdapterQuestion, Class<Basic_database_questionsActivity>) is undefined 

Intent i = new Intent(MyAdapterQuestion.this, Basic_database_questionsActivity.class); 
      Bundle b = new Bundle(); 
      // get the current value of timerStart variable and store it in timerlogic 
      //Log.e(LOGS, "Whatis the value of timerstart inside the intentcalls method" + aInt); 

      b.putInt("timerlogic", aInt); 

입니다.

나는 당신이 어댑터에 텐트를 보낼 수있는 방법의 Bindview 방법

public void bindView(View v, Context context, Cursor c) { 

    if(radiopos1.isChecked()) 
     { 

      // i want to update my main activity 
    // this method increment the correct answer by one I want to get that value and //pass it back to the activity  
    correctAnswer(); 

     } 

    } 
+0

하나님을 사랑하고 코드를 형식화하는 법을 배우십시오! 이건 너무 불쾌해서 거의 불쾌 해! –

답변

2

호 내부 카운터가 있습니다. 액티비티는 어댑터와 통신 할 수 있도록 어댑터를 생성했습니다. 어느 등, 생성자에 매개 변수를 전달,

편집하는 방법을 호출하여 : 어댑터가 활동의 메소드를 호출 할 필요가있는 경우 코드 예제

을 추가, 당신은 이런 식으로 뭔가를 할 수 :

를 Basic_database_questionsActivity에서

// Stores a reference to the owning activity 
private Basic_database_questionsActivity activity; 

// Sets the owning activity (caller should call this immediately after constructing 
// the adapter) 
public void setActivity(Basic_database_questionsActivity activity) { 
    this.activity = activity; 
} 

// When you want to call a method in your activity (to get or set data), you do 
// something like this: 
activity.setCorrectAnswer(answer); 

:

MyAdapterQuestion에서

아이디어를 얻길 바랍니다. 필요한 경우 Adapter가 Activity에 대한 참조를 가져와 메소드를 호출 할 수있는 방법이 필요합니다.

참고 : 더 나은 프로그래밍 스타일은 Activity를 매개 변수로 어댑터 생성자에 포함시키는 것이지만 어댑터 생성자에 대한 코드를 게시하지 않았기 때문에 너무 혼동하지 않으려했습니다.

+0

예를 들어 데이비드에게 내가 그 대답을 분명히 이해하는지 확인해 주시겠습니까? – alex

+0

코드 예제를 추가했습니다. 문제를 해결 했습니까? 도움이 더 필요하십니까? –