2014-10-21 4 views
0

나는 목록의 모든 게시물에 대해 목록보기를 만들었습니다. 내가 원하는 것은 목록에서 자식을 클릭하면 해당 특정 게시물과 관련 설명을 보여주는 다른 활동을 열어 줄 것입니다. 질문은 클릭 한 항목을 알 수있는 방법과 해당 특정 게시물을 표시하는 방법입니다. 다음 활동에서 ParseObject 목록보기에서 메시지를 클릭하면 메시지가 다음 활동에 표시됩니다.Android 및 구문 분석

이 문제를 해결하면 매우 감사할만한 메시지입니다.

답변

1

이 코드를보십시오 :

직렬화

listView.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> adapter, View v, int position, 
        long arg3) { 

       try 
       { 
        Log.v("position",position); // hear is your list item position 
        MyClass obj = new MyClass(); // Class must be implements with Serializable 
        Intent showintent = new Intent(context,<activity class to open>); 
        showcontactintent.putExtra("obj",obj); 
        startActivity(showintent); 
       } 
       catch(Exception e) 
       { 
        e.printStackTrace(); 
       } 
      } 

     }); 
+0

listView는 parseobjects (Posts)를 사용하여 채워지 며 listitem (특정 게시물)을 클릭하면 해당 항목 (게시물)이 내 새 활동에서 끌어 당겨지기를 원합니다. 하지만 내 새 활동에서 그 (게시물) listitem을 어떻게 반영 할 수 있습니까? 그래서 그 게시물에 대한 모든 댓글을 다음 활동에 표시 할 수 있습니다. –

+0

목록에 ID를 설정하십시오. 데이터베이스 행 기본 키와 동일합니다. listitem의 위치를 ​​사용하여 데이터베이스에서 특정 행을 가져올 수 있습니다. – Amy

+0

도움을 주셔서 감사합니다! –

0

를 사용하여 객체를 구현하십시오 : 관계형 데이터

객체가 다른 객체와의 관계를 가질 수 있습니다. 이 동작을 모델링하려면, 임의의 ParseObject를 다른 ParseObject의 값으로서 사용할 수 있습니다. 내부적으로, Parse 프레임 워크는 일관성을 유지하기 위해 참조 된 객체를 한 곳에 저장합니다.

예를 들어 블로그 앱의 각 댓글은 하나의 게시물에 해당 할 수 있습니다. 하나의 코멘트와 새 게시물을 작성하려면, 당신은 쓸 수 :

// Create the post 
ParseObject myPost = new ParseObject("Post"); 
myPost.put("title", "I'm Hungry"); 
myPost.put("content", "Where should we go for lunch?"); 

// Create the comment 
ParseObject myComment = new ParseObject("Comment"); 
myComment.put("content", "Let's do Sushirrito."); 

// Add a relation between the Post and Comment 
myComment.put("parent", myPost); 

// This will save both myPost and myComment 
myComment.saveInBackground(); 

을 또한과 같이 그들의하며 Object를 사용하여 객체를 연결할 수 있습니다

객체를 가져올 때 기본적으로
// Add a relation between the Post with objectId "1zEcyElZ80" and the comment 
myComment.put("parent", ParseObject.createWithoutData("Post", "1zEcyElZ80")); 

, 관련 ParseObjects을 가져 오지 않습니다. 그들과 같이 가져온 때까지이 개체의 값을 검색 할 수 없습니다 :

fetchedComment.getParseObject("post") 
    .fetchIfNeededInBackground(new GetCallback<ParseObject>() { 
     public void done(ParseObject post, ParseException e) { 
      String title = post.getString("title"); 
      // Do something with your new title variable 
     } 
    }); 

또한 ParseRelation 개체를 사용하여 다 대다 관계를 모델링 할 수 있습니다. 릴레이션에서 모든 ParseObject를 한꺼번에 다운로드 할 필요가 없다는 점을 제외하면 List와 비슷합니다. 이를 통해 ParseRelation은 List 접근 방식보다 더 많은 개체로 확장 할 수 있습니다. 예를 들어, 사용자는 자신이 좋아할만한 게시물을 많이 가질 수 있습니다. 이 경우 사용자가 getRelation을 사용하여 좋아하는 게시물 집합을 저장할 수 있습니다. 더 읽기

ParseUser user = ParseUser.getCurrentUser(); 
ParseRelation<ParseObject> relation = user.getRelation("likes"); 
relation.add(post); 
user.saveInBackground(); 
You can remove a post from the ParseRelation with something like: 

relation.remove(post); 

: 목록에 게시물을 추가하려면, 코드는 같을 것이다 https://parse.com/docs/android/guide#objects-relational-data

^왜 모든 단어 여기 대신 그냥 링크를 제공하는 복사 했습니까? 구문 분석 링크가 때때로 손상되어 필요한 섹션으로 안내하지 않기 때문에 (대신 단지 https://parse.com/docs/android/guide으로 전송되며 의사가 너무 크기 때문에 찾을 수 없습니다.)