2014-12-10 8 views
1

오랫동안 질문에 대해 미안하다.중첩 쿼리 구문 분석 안드로이드

Android 용 운동 앱을 만드는 구문 분석 사용하기. 내 문제와 관련이있는

데이터베이스 테이블 및 열은 다음과 같습니다

ID 연습 | 이름 | 설명 |

운동

ID를 Musclegroup | 운동 이름 | | 사용자 ID

WorkoutExercises는

ID (기본적으로 둘 사이에 테이블을 조인) workoutID (포인터) | exerciseID (포인터)

그래서 사용자는 운동을 만들고 원하는 운동을 추가 할 수 있습니다.

은 지금까지 이미 완료했습니다 :

  • 사용자는
  • 목록 프로파일 업데이트, 해당 그룹에
  • 가입/로그인/로그 아웃을 연습을보고, 카테고리로 이동 근육 그룹을 검색 할 수 있습니다 현재 운동 (그들 안에있는 운동이 아닌) - 방금 ​​db에 운동에 약간의 운동을 입력했습니다. 새로운 운동을 삽입하기를 염려하기 전에 운동에서 현재 운동을 질의하는 것에 집착했습니다.

문제 : 나는 사용자가 예를 클릭 그래서 일단 운동 이름을 얻기 위해 중첩 된 쿼리를 할 노력하고있어

. 등 운동은 그것이 목록을 가져와야합니다. 데 드리프트, 행, 친 업

SQL에서 그래서 기본적으로

내가 원하는 : 연습 에서

선택 이름 가의 ID

것들 내가 사투를 벌인거야 (workoutexercises에서 exerciseID을 선택이 WorkoutID = xxxx는 곳) 여기서

에 :

  1. 내가 인터넷에서 읽은 내용에서, 포인터에 대한 중첩 된 쿼리를 만들기 내가 query.include ("exerciseID")를 사용할 필요가; Parse에게 내가 Exercise에 사용할 수있는 Full Exercise 항목을 포함하도록 말할 것인가? 틀린 경우에 나를 정정하십시오? 아래 코드 - 제대로 했습니까?

  2. 나는 쿼리 데이터가 데이터를 나열하는 사용자 지정 어댑터에 저장되는 http://www.michaelevans.org/blog/2013/08/14/tutorial-building-an-android-to-do-list-app-using-parse/의 메서드를 사용하여 배웠고 사용했습니다. 그것은 getter 및 setter를 사용하여 String/int 값을 저장/검색하지만 여전히 포인터 내에서 문자열을 가져 오는 데 getters를 사용합니까?

EG.

public String getName() 
    { 
     return getString("name"); 
    } 

내가 그 포인터 "를 통해"나는 여전히 단지의 parseObject을 얻기에 관해서는 반대 문자열 이름 값을 받고 있어요 가정 운동 테이블 메신저에있어 한 번 같이?

지금까지는 맞춤 어댑터를 사용하여 3 개의 항목을 넣었지만 필요한 운동 이름의 텍스트를 가져 오지 않는다는 것을 보여주는 두 개의 수평 막대를 화면에 표시 할 수있었습니다. 중첩 쿼리

내 스크린 샷을보고 무슨 뜻인지 확인해보십시오.

미리 도움을 주셔서 감사합니다. 지금까지

검색어 :

public void getcurrentExercisesInWorkout() { 
    //set progress bar 
    setProgressBarIndeterminateVisibility(true); 
    ParseQuery<WorkoutExercises> query = ParseQuery.getQuery("WorkoutExercises"); 
    query.include("exerciseId"); 
    query.whereEqualTo("workoutId", mWorkoutId); 

    query.findInBackground(new FindCallback<WorkoutExercises>() { 
     @Override 
     public void done(List<WorkoutExercises> workoutExercises, ParseException error) { 
      if (workoutExercises != null) { 

       mWorkoutExercisesAdapter.clear(); 
       mWorkoutExercisesAdapter.addAll(workoutExercises); 

      } else { 
       Log.d("error", error.getMessage()); 
      } 
     } 
    }); 
    //stop progress bar 
    setProgressBarIndeterminateVisibility(false); 
} 

사용자 지정 목록 어댑터 :

//constructor - get current state of parsed object and list of objects retrieved from workout 
public WorkoutExercisesAdapter(Context context, List<WorkoutExercises> objects) { 
    super(context, R.layout.row_item, objects); 
    this.mContext = context; 
    this.mWorkoutExercises = objects; 
} 
public View getView(int position, View convertView, ViewGroup parent) 
{ 
    //put each item into the listview 
    if(convertView == null) 
    { 
     LayoutInflater mLayoutInflater = LayoutInflater.from(mContext); 
     convertView = mLayoutInflater.inflate(R.layout.row_item,null); 
    } 
    WorkoutExercises workoutExercises = mWorkoutExercises.get(position); 

    TextView nameView = (TextView) convertView.findViewById(R.id.row_name); 
    //this just calls a String getter - which isn't working - need it to get the Exercise name from within the pointer 
    nameView.setText(workoutExercises.getWorkoutExercise()); 
    return convertView; 
} 

WorkoutExercises (저장 게터) 나는 그대로를 볼 수있는 디버그 모드에서 안드로이드 Studio를 실행

@ParseClassName("WorkoutExercises") 
public class WorkoutExercises extends ParseObject { 
    public String exName; 
    public WorkoutExercises() 
    { 
    } 
    public String getWorkoutExercise() 
    { 
     return getString("name"); 
    } 
} 

데이터를 텍스트 필드에 넣으려고합니다 (스크린 샷을 참조하십시오 - 그 값을 얻으려면 어떻게해야합니까?) 스크린 샷보기 Workout Name

Exercise Name missing

debug mode 아래 NOW 일하기 - 결과를! 먼저

enter image description here

+0

이 workoutExercises.getWorkoutExercise()'의 구현을 제공하시기 바랍니다 문제에 대한 몇 가지 빛을 비춰' – gio

+0

는 물론, 위의 추가 스크린 샷. 고마워요. –

+0

정확하게 이해했다면,'nameView.setText (((Exercises) workoutExercises.getWorkoutExercise()) .getName());'Exercises 서브 클래스가 있다고 가정하면 WorkoutExercises의 경우), 그렇지 않으면'nameView.setText (workoutExercises.getWorkoutExercise(). get ('name'));'. 후자는 항상 포함되어있는 포인터가 항상 ParseObject (ParseObject를 확장하는 하위 클래스)로 해석되므로 'get (nameOfKey)'및 'put (key, value)'호출을 항상 지원해야하므로 두 경우 모두에서 작동해야합니다. – cYrixmorten

답변

2

는 WorkoutExercises 오브젝트 : ALTER

@ParseClassName("WorkoutExercises") 
public class WorkoutExercises extends ParseObject { 
    //public String exName; 
    public static final String workoutID = "workoutID" 
    public static final String exerciseID = "exerciseID" 

    public Exercises getWorkoutExercise() { 
     return (Exercises)getParseObject(exerciseID); 
    } 

    public WorkoutExercises() 
    { 
     // not sure if it is allowed to define your own constructor? 
     // just a note 
    } 

    // WorkoutExercises does not have a 'name' col 
    //public String getWorkoutExercise() 
    //{ 
    // return getString("name"); 
    //} 
} 

나는 연습 적어도 같은 포함되어 있다고 가정 : workoutID 포함 WorkoutExercises에 쿼리 지금

@ParseClassName("Exercises") 
public class Exercises extends ParseObject { 

    public static final String name = "name" 


    public String getName() 
    { 
     return getString(name); 
    } 

} 

을, Exercises 개체가 가져온 쿼리에 채워집니다. 이것은 당신이이 운동의 이름을 얻기 위해 다음과 같은 작업을 수행 할 수 의미 객체 :

// workoutExercises returned from a query including workoutID 
Exercises exercise = workoutExercises.getWorkoutExercise(); 
String name = exercise.getName(); 

// if Exercises has getters for description and Musclegroup 
String description = exercise.getDescription(); 
String musclegroup= exercise.getMusclegroup(); 

희망이

+0

오 마이 갓! 당신은 전설적이다! 나는 내가 얼마나 행복한지를 표현할 수 없다. 그게 완벽 했어! 절대적으로 일했다. 나는 매우 황홀 해! 도와 주셔서 너무 감사합니다. 긴 질문이었습니다. 또한 쿼리 완료 후 회전을 멈추라 고 말한 것처럼 진행 표시 줄 표시기를 옮겼습니다. 오늘 밤 집에 가서 코딩을 기다릴 수 없어! 또한 질문의 맨 아래에 스크린 샷을 추가하여 결과를 표시했습니다. –

+1

Hehe 내가 기꺼이 도와 드리겠습니다;) 행복한 코딩. 그런데 결과를 보여주기 위해 자신의 어댑터를 만든 것처럼 보입니다. parse.com의 사람들은 다음과 같이 알려줍니다. https://www.parse.com/docs/android_guide#ui -queryadapter. 쿼리를 말하기 위해 '숨겨져 있기'때문에 살펴보고, 'onLoading()'과 'onLoaded()'와 같은 콜백에 접근 할 수 있도록 해 줄 것을 제안합니다. 그러면 로딩 인디케이터를 쉽게 추가 할 수 있습니다. – cYrixmorten

+0

우수. 고마워, 나는 그것을 몰랐다. 네, 맞춤 어댑터가 있습니다. 파스 (Parse)의 책에 대한 기사가 있습니다. –