我已经建立了一个讨论论坛,登录的人可以提问,主论坛显示不同用户提出的所有问题。每个人都可以回答这个问题并评价。
问题是什么时候添加问题活动的问题会回到讨论论坛而不是刷新。我想要的是,一旦提出问题,它应该在讨论论坛中显示,用户应该能够修改和删除该问题。一切都是动态的,如何删除动态数据。
这是我的论坛代码
package com.example.pitechnologies.pkguru.fragment;
public class DiscussionForumFragment extends Fragment {
TextView title;
RelativeLayout askquestion;
public View view;
UserProfileData userProfileData;
String U_id;
EditText que, desc;
TextView btnask;
String uname;
LinearLayout linearLayout;
ImageView imgSpoon;
final List<Model_Forum> unilist = new ArrayList<>();
private static String TAG = DiscussionForumFragment.class.getSimpleName();
private RecyclerView forumrecyclerView;
private ForumList_Adapter forumAdapter;
public DiscussionForumFragment() {
}
@Override
public void onStart() {
((AppCompatActivity) getActivity()).getSupportActionBar().hide();
super.onStart();
}
@Override
public void onResume() {
super.onResume();
((AppCompatActivity) getActivity()).getSupportActionBar().hide();
// forumdata();
}
@Override
public void onStop() {
super.onStop();
((AppCompatActivity) getActivity()).getSupportActionBar().show();
}
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_discussion_forum, container, false);
title = (TextView) view.findViewById(R.id.forumtitle);
title.setText("DISCUSSION FORUM");
askquestion = (RelativeLayout) view.findViewById(R.id.askquestion);
askquestion.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(PreferenceHelper.getInstance(getActivity()).getSemid() == null) {
Intent intent = new Intent(getActivity(), ActivityLoginSignUp.class);
startActivity(intent);
}else {
Intent intent = new Intent(getActivity(), ActivityQuestionaire.class);
intent.putExtra("uu_id", U_id);
startActivity(intent);
}
}
});
forumrecyclerView = (RecyclerView) view.findViewById(R.id.recyclerview_forum);
forumrecyclerView.setHasFixedSize(true);
forumrecyclerView.setLayoutManager(new LinearLayoutManager(DiscussionForumFragment.this.getActivity()));
forumAdapter = new ForumList_Adapter(DiscussionForumFragment.this.getContext(), unilist);
forumrecyclerView.setAdapter(forumAdapter);
forumrecyclerView.setNestedScrollingEnabled(false);
imgSpoon = (ImageView) view.findViewById(R.id.image_spoon);
linearLayout = (LinearLayout) view.findViewById(R.id.pg_loader);
linearLayout.setVisibility(View.INVISIBLE);
forumdata();
return view;
}
public void forumdata() {
unilist.clear();
/* final ProgressDialog pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading...");
pDialog.show();*/
linearLayout.setVisibility(View.VISIBLE);
ObjectAnimator flip = ObjectAnimator.ofFloat(imgSpoon, "rotationY", 0f, 180f);
flip.setDuration(800);
flip.setRepeatCount(Animation.INFINITE);
flip.start();
StringRequest strReq = new StringRequest(Request.Method.POST,
URLconstant.FORUM, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
try {
JSONObject data = new JSONObject(response);
Log.d("data", data.toString());
JSONArray datarray = data.getJSONArray("data");
for (int i = 0; i < datarray.length(); i++) {
JSONObject secondobj = datarray.getJSONObject(i);
Log.d("secondobj", secondobj.toString());
Model_Forum model_forum = new Model_Forum();
model_forum.mforum_id = secondobj.getString("forum_id");
model_forum.mqst = secondobj.getString("qst");
model_forum.mqst_description = secondobj.getString("qst_description");
model_forum.mqst_uid = secondobj.getString("qst_uid");
model_forum.muser_id = secondobj.getString("user_id");
model_forum.mfullname = secondobj.getString("fullname");
model_forum.muniver_id = secondobj.getString("univer_id");
model_forum.mbranchid = secondobj.getString("branchid");
model_forum.msemid = secondobj.getString("semid");
model_forum.mcollegeid = secondobj.getString("collegeid");
model_forum.muser_image = secondobj.getString("user_image");
model_forum.mq_date = secondobj.getString("q_date");
model_forum.mq_time = secondobj.getString("q_time");
unilist.add(model_forum);
}
if (getContext() != null) {
/* forumAdapter = new ForumList_Adapter(DiscussionForumFragment.this.getContext(), unilist);
forumrecyclerView.setAdapter(forumAdapter);*/
forumAdapter.notifyDataSetChanged();
}
} catch (JSONException e) {
e.printStackTrace();
}
// pDialog.dismiss();
linearLayout.setVisibility(View.INVISIBLE);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
// pDialog.dismiss();
linearLayout.setVisibility(View.INVISIBLE);
}
});
MySingleton.getInstance(getActivity()).addToRequestQueue(strReq);
}