我正在开发基于Navigation Drawer
的Android应用程序。 NavMainActivity
处理片段。 EventFragment
,HomeFragment
,ProfileFragment
等
我使用 Parse SDK 进行后台作业。 Parse做得很好。
但是在EventFragment
课程中,TextView
的{{1}}方法无法执行任何操作。我检查了这个问题并使用setText()
和Snackbar
来测试我的后台服务运行良好。
Toast
public class EventFragment extends Fragment implements View.OnClickListener {
/*
Initiliazing the params and our view.
*/
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
View view;
boolean isPressed = false;
private String mParam1;
private String mParam2;
public String eventDescription;
public ParseFile userImage;
private OnFragmentInteractionListener mListener;
public EventFragment() {
// Required empty public constructor
}
public static EventFragment newInstance(String param1, String param2) {
EventFragment fragment = new EventFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/*
FloatingAB used for material design guidelines.
We listen for clicks but in this version user can click many times we need to
implement opposite button reaction like " Participate " and " Not Participate " state changes.
*/
view= inflater.inflate(R.layout.fragment_event, container, false);
FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
fab.setOnClickListener(this);
ParseQuery<ParseObject> query = ParseQuery.getQuery("EventData");
query.whereEqualTo("objectId", "uEglVemWEF");
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (object == null) {
Log.d("EventData", "The get the first method request failed!");
} else {
eventDescription = object.getString("eventContext");
userImage = object.getParseFile("eventPhoto");
Snackbar.make(view, eventDescription, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
});
TextView z = (TextView)view.findViewById(R.id.eventDescriptionText);
z.setText(eventDescription);
if (ParseUser.getCurrentUser().getBoolean("eventA")) {
fab.setImageResource(R.drawable.ic_highlight_remove_24dp);
isPressed =true;
}
return view;
}
有什么想法吗?
答案 0 :(得分:0)
您尝试异步(在另一个线程上)获取eventDescription,然后使用主线程中的值。到目前为止它肯定还是空的。尝试在done()
query.getFirstInBackground
回调中设置TextView