Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import leaynik.api.API;
- import leaynik.api.JsonParsing;
- import org.json.JSONArray;
- import org.json.JSONException;
- import Le3ynik.defs.ConnectionExector.HTTPResponse;
- import Le3ynik.defs.ConnectionExector.ResponseType;
- import Le3ynik.defs.ConnectionExector.onHttpRequestListener;
- import Le3ynik.defs.DisasesItem;
- import Le3ynik.ui.Disases_listView;
- 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 Diases_Fragment extends Fragment {
- public static Diases_Fragment newInstance() {
- Diases_Fragment fragment = new Diases_Fragment();
- Bundle args = new Bundle();
- return fragment;
- }
- Disases_listView Adapter;
- ListView list;
- ProgressBar progress;
- ArrayList<DisasesItem> Disases = new ArrayList<DisasesItem>();
- TextView reload;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.listview, null);
- list = (ListView) v.findViewById(R.id.zfta);
- progress = (ProgressBar) v.findViewById(R.id.list_prog);
- Adapter = new Disases_listView(getActivity(), Disases);
- reload = (TextView) v.findViewById(R.id.reload);
- list.setAdapter(Adapter);
- list.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
- long arg3) {
- // Intent i = new Intent(getActivity(), Disase_Details.class);
- // i.putExtra("mard", Disases.get(pos));
- // startActivity(i);
- // Disase_Details details = new Disase_Details();
- // ((Home) getActivity()).replaceDieasesFragment(details,
- // Disases.get(pos));
- Intent i = new Intent(getActivity(), Disase_Details.class);
- i.putExtra("mard", Disases.get(pos));
- startActivity(i);
- }
- });
- GetAllDiases();
- reload.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- GetAllDiases();
- }
- });
- final FloatingView floatinView = (FloatingView) v
- .findViewById(R.id.FloatingView);
- if (floatinView != null) {
- floatinView.setScrollableViewId(R.id.zfta);
- floatinView.setVisibility(View.GONE);
- }
- return v;
- }
- private void GetAllDiases() {
- API api = new API(getActivity());
- if (api.isNetworkConnected()) {
- progress.setVisibility(View.VISIBLE);
- list.setVisibility(View.GONE);
- reload.setVisibility(View.GONE);
- api.getAllDisease(onGetAllDiases);
- } else {
- Toast.makeText(getActivity(),
- getResources().getString(R.string.nointernet), 2000).show();
- list.setVisibility(View.GONE);
- reload.setVisibility(View.VISIBLE);
- }
- }
- onHttpRequestListener onGetAllDiases = new onHttpRequestListener() {
- @Override
- public void onHttpResult(HTTPResponse response, String senddata) {
- progress.setVisibility(View.GONE);
- list.setVisibility(View.VISIBLE);
- if (response.response == ResponseType.SUCESS) {
- try {
- JSONArray arr = (JSONArray) response.data;
- JsonParsing json = new JsonParsing();
- for (int i = 0; i < arr.length(); i++)
- Disases.add(json.GetDisesInfo(arr.getJSONObject(i)));
- Adapter.notifyDataSetChanged();
- } catch (JSONException e) {
- e.printStackTrace();
- }
- } else {
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement