Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package leaynik.co.com;
- import java.util.ArrayList;
- import leaynik.api.API;
- import leaynik.api.JsonParsing;
- import org.json.JSONArray;
- import org.json.JSONException;
- import Le3ynik.defs.ConnectionExector.ResponseType;
- import Le3ynik.defs.ConnectionExector.onHttpRequestListener;
- import Le3ynik.defs.QuestionItem;
- import Le3ynik.ui.ListViewAdapter;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemClickListener;
- import android.widget.ListView;
- import android.widget.ProgressBar;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.gruposca.android.floatingview.ui.views.FloatingView;
- public class AllPosts extends Fragment implements OnClickListener {
- int mNum;
- ListView Ques_list;
- ProgressBar list_prog;
- ListViewAdapter adapter;
- ArrayList<QuestionItem> Questions = new ArrayList<QuestionItem>();
- TextView reload;
- static AllPosts newInstance(int num) {
- AllPosts f = new AllPosts();
- Bundle args = new Bundle();
- args.putInt("num", num);
- f.setArguments(args);
- return f;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mNum = getArguments() != null ? getArguments().getInt("num") : 1;
- }
- onHttpRequestListener onGetAllPosts = new onHttpRequestListener() {
- @Override
- public void onHttpResult(
- Le3ynik.defs.ConnectionExector.HTTPResponse response,
- String senddata) {
- list_prog.setVisibility(View.GONE);
- if (response.response == ResponseType.SUCESS) {
- try {
- Questions.clear();
- JSONArray arr = (JSONArray) response.data;
- JsonParsing json = new JsonParsing();
- for (int i = 0; i < arr.length(); i++)
- Questions
- .add(json.getQuestionData(arr.getJSONObject(i)));
- adapter.notifyDataSetChanged();
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else {
- Toast.makeText(getActivity(), response.value, 3000).show();
- }
- }
- };
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.listview, container, false);
- Ques_list = (ListView) v.findViewById(R.id.zfta);
- list_prog = (ProgressBar) v.findViewById(R.id.list_prog);
- reload = (TextView) v.findViewById(R.id.reload);
- adapter = new ListViewAdapter(getActivity(), Questions, 0);
- Ques_list.setAdapter(adapter);
- Ques_list.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
- long arg3) {
- Intent i = new Intent(getActivity(), ViewAnswers.class);
- i.putExtra("post", Questions.get(pos));
- startActivity(i);
- }
- });
- getAllPosts();
- reload.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- getAllPosts();
- }
- });
- final FloatingView floatinView = (FloatingView)v. findViewById(R.id.FloatingView);
- if (floatinView != null) {
- floatinView.setScrollableViewId(R.id.zfta);
- floatinView.setOnClickListener(this);
- }
- return v;
- }
- private void getAllPosts() {
- API api = new API(getActivity());
- if (api.isNetworkConnected()) {
- list_prog.setVisibility(View.VISIBLE);
- reload.setVisibility(View.GONE);
- api.getAllPosts(onGetAllPosts);
- } else {
- Toast.makeText(getActivity(), getResources().getString(R.string.nointernet), 2000)
- .show();
- Ques_list.setVisibility(View.GONE);
- reload.setVisibility(View.VISIBLE);
- }
- }
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- startActivity(new Intent(getActivity(), Add_Question.class));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement