解析:解析查询<parseobject>从onListItemClick获取链接2数据库</parseobject>

时间:2014-12-05 03:40:42

标签: java android pointers parse-platform

我在Parse中有两个数据库: 1)除 2)Subject_section

我想使用指针检索数据。 在我的&#34;主题&#34;表,有一个&#34;部分&#34;指向表&#34; Subject_section&#34;的指针。 我如何使用onListItemClick来检索和显示我的数据&#34;主题&#34;表格和数据在我的&#34;指针&#34; Subject_section。

我的对象包含指向其他对象的指针,以返回填充的那些(显然)内部对象。

http://i.imgur.com/Y9upOGP.png

http://i.imgur.com/bTl6vju.png

我的代码Subject_detail.java:

 ParseQuery<ParseObject> query = ParseQuery.getQuery("Subject");
    query.include("Subject_section");
        @Override
        public void done(List<ParseObject> postList, ParseException e) {
            if (e == null) {
                posts.clear();
                Toast.makeText(getApplicationContext(), "Retrieve successfully!",
                        Toast.LENGTH_SHORT).show();
                for (ParseObject post : postList) {
                  //  ParseObject section=post.getParseObject("Subject_section");

                    Subject subject = new Subject(
                            post.getString("Subject_code"),
                            post.getString("Subject_name"),
                            post.getParseObject("Subject_section"));

                    posts.add(subject);

                }
                ((ArrayAdapter<Subject>) getListAdapter()).notifyDataSetChanged();
            }
        }
    });
     protected void onListItemClick(ListView l, View v, int position, long id){
    super.onListItemClick(l,v,position,id);

    ParseObject item=(ParseObject) l.getAdapter().getItem(position);
    String section=item.getParseObject("Subject_section").toString();

    Subject subject=posts.get(position);      
    Intent intent=new Intent(this,Edit_Subjects.class);
    intent.putExtra("subjectCode",subject.getSubject_code());
    intent.putExtra("subjectName",subject.getSubject_name());
    intent.putExtra("SubjectSection",section);

    startActivity(intent);
}

我在subject.java中的代码

public class Subject {
private String Subject_code;
private String Subject_name;
private ParseObject Subject_section;

Subject(String subjectCode,String subjectName,ParseObject subjectSection){
Subject_code=subjectCode;
Subject_name=subjectName;
Subject_section=subjectSection;

public String getSubject_code(){
    return Subject_code;
}
public void setSubject_code(String code){
    this.Subject_code=code;
}

public String getSubject_name(){return Subject_name;}
public void setSubject_name(String name){ this.Subject_name=name;}

public ParseObject getSubject_section(){return Subject_section;}
public void setSubject_section(ParseObject subject_section) {
    Subject_section = subject_section;
}

public String toString (){
return this.getSubject_code();
}
}

我的问题是在我班上显示结果。我无法从Subject_detail.java获取ParseObject指针。

如何让指针指向并从&#34; Subject_section&#34;中检索数据?类。

我在Edit_Subject.java中的代码

private EditText subject_code;
private EditText subject_name;
private EditText section;
private Subject subject;
private Subject_section subject_section;
@OVerride
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_subjects);
Intent intent=this.getIntent();
subject_code =(EditText)findViewById(R.id.subject_code);
subject_name=(EditText)findViewById(R.id.subject_name);
section=(EditText)findViewById(R.id.section);

 if (intent.getExtras()!=null){
 subject=new Subject(intent.getStringExtra("subjectCode"),
                     intent.getStringExtra("subjectName"),
                     intent.getStringExtra("Subject_section"));//Error here getting ParseObject

 subject_code.setText(subject.getSubject_code());
 subject_name.setText(subject.getSubject_name());
 section1.setText(subject_section.getSection_1());
 section2.setText(subject_section.getSection_2());
 section3.setText(subject_section.getSection_3());
 section4.setText(subject_section.getSection_4());

  }

1 个答案:

答案 0 :(得分:0)

您需要致电fetchIfNeeded()。可能无法获取指针中的信息,尤其是第一次访问时。

ParseObject child = parentParseObject.getParseObject("child");

try {
    child.fetchIfNeeded(); // fetches information from Parse
} catch (ParseException ex) {ex.printStackTrace();}