Advertisement
minafaw3

allpost leaynik

Dec 30th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. package leaynik.co.com;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import leaynik.api.API;
  6. import leaynik.api.JsonParsing;
  7.  
  8. import org.json.JSONArray;
  9. import org.json.JSONException;
  10.  
  11. import Le3ynik.defs.ConnectionExector.ResponseType;
  12. import Le3ynik.defs.ConnectionExector.onHttpRequestListener;
  13. import Le3ynik.defs.QuestionItem;
  14. import Le3ynik.ui.ListViewAdapter;
  15. import android.content.Intent;
  16. import android.os.Bundle;
  17. import android.support.v4.app.Fragment;
  18. import android.view.LayoutInflater;
  19. import android.view.View;
  20. import android.view.View.OnClickListener;
  21. import android.view.ViewGroup;
  22. import android.widget.AdapterView;
  23. import android.widget.AdapterView.OnItemClickListener;
  24. import android.widget.ListView;
  25. import android.widget.ProgressBar;
  26. import android.widget.TextView;
  27. import android.widget.Toast;
  28.  
  29. import com.gruposca.android.floatingview.ui.views.FloatingView;
  30.  
  31. public class AllPosts extends Fragment implements OnClickListener {
  32. int mNum;
  33. ListView Ques_list;
  34. ProgressBar list_prog;
  35. ListViewAdapter adapter;
  36. ArrayList<QuestionItem> Questions = new ArrayList<QuestionItem>();
  37.  
  38. TextView reload;
  39.  
  40. static AllPosts newInstance(int num) {
  41. AllPosts f = new AllPosts();
  42. Bundle args = new Bundle();
  43. args.putInt("num", num);
  44. f.setArguments(args);
  45.  
  46. return f;
  47. }
  48.  
  49. @Override
  50. public void onCreate(Bundle savedInstanceState) {
  51. super.onCreate(savedInstanceState);
  52. mNum = getArguments() != null ? getArguments().getInt("num") : 1;
  53.  
  54. }
  55.  
  56. onHttpRequestListener onGetAllPosts = new onHttpRequestListener() {
  57.  
  58.  
  59. @Override
  60. public void onHttpResult(
  61. Le3ynik.defs.ConnectionExector.HTTPResponse response,
  62. String senddata) {
  63.  
  64. list_prog.setVisibility(View.GONE);
  65. if (response.response == ResponseType.SUCESS) {
  66. try {
  67. Questions.clear();
  68. JSONArray arr = (JSONArray) response.data;
  69. JsonParsing json = new JsonParsing();
  70. for (int i = 0; i < arr.length(); i++)
  71.  
  72. Questions
  73. .add(json.getQuestionData(arr.getJSONObject(i)));
  74. adapter.notifyDataSetChanged();
  75. } catch (JSONException e) {
  76. // TODO Auto-generated catch block
  77. e.printStackTrace();
  78. }
  79.  
  80. } else {
  81. Toast.makeText(getActivity(), response.value, 3000).show();
  82. }
  83.  
  84. }
  85. };
  86.  
  87. @Override
  88. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  89. Bundle savedInstanceState) {
  90. View v = inflater.inflate(R.layout.listview, container, false);
  91. Ques_list = (ListView) v.findViewById(R.id.zfta);
  92. list_prog = (ProgressBar) v.findViewById(R.id.list_prog);
  93. reload = (TextView) v.findViewById(R.id.reload);
  94. adapter = new ListViewAdapter(getActivity(), Questions, 0);
  95. Ques_list.setAdapter(adapter);
  96. Ques_list.setOnItemClickListener(new OnItemClickListener() {
  97.  
  98. @Override
  99. public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
  100. long arg3) {
  101.  
  102. Intent i = new Intent(getActivity(), ViewAnswers.class);
  103. i.putExtra("post", Questions.get(pos));
  104. startActivity(i);
  105. }
  106. });
  107. getAllPosts();
  108. reload.setOnClickListener(new OnClickListener() {
  109.  
  110. @Override
  111. public void onClick(View arg0) {
  112. // TODO Auto-generated method stub
  113. getAllPosts();
  114. }
  115. });
  116. final FloatingView floatinView = (FloatingView)v. findViewById(R.id.FloatingView);
  117. if (floatinView != null) {
  118. floatinView.setScrollableViewId(R.id.zfta);
  119. floatinView.setOnClickListener(this);
  120. }
  121.  
  122. return v;
  123. }
  124.  
  125. private void getAllPosts() {
  126. API api = new API(getActivity());
  127.  
  128. if (api.isNetworkConnected()) {
  129. list_prog.setVisibility(View.VISIBLE);
  130. reload.setVisibility(View.GONE);
  131. api.getAllPosts(onGetAllPosts);
  132. } else {
  133. Toast.makeText(getActivity(), getResources().getString(R.string.nointernet), 2000)
  134. .show();
  135. Ques_list.setVisibility(View.GONE);
  136. reload.setVisibility(View.VISIBLE);
  137. }
  138. }
  139.  
  140. @Override
  141. public void onClick(View v) {
  142. // TODO Auto-generated method stub
  143. startActivity(new Intent(getActivity(), Add_Question.class));
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement