我在使用ParseObject时遇到问题,首先尝试使用ListActivity但应用程序崩溃了,然后看到堆栈溢出上的几个帖子也没有用,关于Parse类的细节很少
Class Name : Events
Fields: String event_name;
String date;
String time;
String event_venue;
String speaker;
int fee;
String event_description;
当我尝试初始化适配器时,程序中的错误仍然存在。
我的代码如下
Events.java
public class Events extends ParseObject {
private String event_name;
private String date;
private String time;
private String event_venue;
private String speaker;
private int fee;
private String event_description;
public Events(String event_name, String date, String time, String event_venue, String speaker, int fee, String event_description) {
this.event_name = event_name;
this.date = date;
this.time = time;
this.event_venue = event_venue;
this.speaker = speaker;
this.fee = fee;
this.event_description = event_description;
}
public String getEvent_name() {
return event_name;
}
public void setEvent_name(String event_name) {
this.event_name = event_name;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getEvent_venue() {
return event_venue;
}
public void setEvent_venue(String event_venue) {
this.event_venue = event_venue;
}
public String getSpeaker() {
return speaker;
}
public void setSpeaker(String speaker) {
this.speaker = speaker;
}
public int getFee() {
return fee;
}
public void setFee(int fee) {
this.fee = fee;
}
public String getEvent_description() {
return event_description;
}
public void setEvent_description(String event_description) {
this.event_description = event_description;
}
}
Events_Activity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
import java.util.ArrayList;
import java.util.List;
public class Event_Activity extends AppCompatActivity {
private List<Events> mEvents= new ArrayList<Events>();
private String e_name;
private String e_date;
private String e_time;
private String e_venue;
private String e_speaker;
private int e_fee;
private String e_description;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event_);
ParseQuery<Events> event_query = new ParseQuery<Events>("Events");
event_query.findInBackground(new FindCallback<Events>() {
@Override
public void done(List<Events> list, ParseException e) {
if(e != null){
Toast.makeText(Event_Activity.this,"Exception : "+e,Toast.LENGTH_LONG).show();
}
for (Events event : list){
e_name = event.getEvent_name();
e_date = event.getDate();
e_time = event.getTime();
e_venue = event.getEvent_venue();
e_speaker = event.getSpeaker();
e_fee = event.getFee();
e_description = event.getEvent_description();
Events new_event = new Events(e_name,e_date,e_time,e_venue,e_speaker,e_fee,e_description);
mEvents.add(new_event);
}
}
});
ArrayAdapter<Events> value = new ArrayAdapter<Events>(Event_Activity.this,android.R.layout.simple_list_item_1, android.R.id.text1, mEvents);
ListView v = (ListView)findViewById(R.id.eventlistView);
v.setAdapter(value);
activity_event_.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.cse.Event_Activity">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/eventlistView">
</ListView>
</RelativeLayout>