Click here to Skip to main content
15,885,278 members
Home / Discussions / Android
   

Android

 
GeneralRe: Android Studio Pin
Richard MacCutchan5-Dec-15 5:00
mveRichard MacCutchan5-Dec-15 5:00 
QuestionRe: Android Studio Pin
David Crow5-Dec-15 14:19
David Crow5-Dec-15 14:19 
QuestionPass value from Activity to Fragment which in layout in Android Pin
Tirumaleswara Reddy.K4-Dec-15 2:47
Tirumaleswara Reddy.K4-Dec-15 2:47 
AnswerRe: Pass value from Activity to Fragment which in layout in Android Pin
David Crow4-Dec-15 4:17
David Crow4-Dec-15 4:17 
GeneralRe: Pass value from Activity to Fragment which in layout in Android Pin
Member 1335895812-Aug-17 22:19
Member 1335895812-Aug-17 22:19 
QuestionAndroid .png image layer on active camera Pin
mack %GUI%23-Nov-15 6:01
mack %GUI%23-Nov-15 6:01 
AnswerRe: Android .png image layer on active camera Pin
Afzaal Ahmad Zeeshan4-Dec-15 3:13
professionalAfzaal Ahmad Zeeshan4-Dec-15 3:13 
Questionwhy is my fragment not displaying anything Pin
dananddarshan17-Nov-15 23:48
dananddarshan17-Nov-15 23:48 
package com.lingme.anand.lingme.Activity.Fragments;

import android.app.ProgressDialog;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.lingme.anand.lingme.Activity.Adapters.NecklaceRecyclerAdapter;
import com.lingme.anand.lingme.Activity.Adapters.PopularRecyclerAdapter;
import com.lingme.anand.lingme.Activity.DetailsActivity;
import com.lingme.anand.lingme.Activity.Listeners.EndlessRecyclerOnScrollListener;
import com.lingme.anand.lingme.Activity.Listeners.EndlessScroller;
import com.lingme.anand.lingme.Activity.Listeners.OnItemSelectedListener;
import com.lingme.anand.lingme.Activity.Pojo.HomePopular;
import com.lingme.anand.lingme.Activity.Pojo.ListProduct;
import com.lingme.anand.lingme.R;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
* Created by nepal on 18/11/2015.
*/
public class DisplayingFragment extends Fragment implements OnItemSelectedListener {
private ConnectivityManager connectivityManager;
private NetworkInfo networkInfo;
private RecyclerView recyclerView;
private String dbname;
private ImageView imageView;
private FragmentManager fragmentManager;
private FragmentTransaction fragmentTransaction;
private NecklaceRecyclerAdapter necklaceRecyclerAdapter;
private List<listproduct> listProducts = new ArrayList<listproduct>();
private ProgressDialog progressDialog;

int count = 2;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
connectivityManager = (ConnectivityManager) getActivity().getSystemService(getActivity().CONNECTIVITY_SERVICE);
networkInfo = connectivityManager.getActiveNetworkInfo();
View view;
if (networkInfo != null && networkInfo.isConnected()) {
view = inflater.inflate(R.layout.list_product, container, false);
dbname = getArguments().getString("dbname");
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_list_product);
final LinearLayoutManager layoutManager = new GridLayoutManager(getActivity(), 3);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);

updateList(dbname);


recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener(layoutManager) {
@Override
public void onLoadMore(int page) {
int lastFirstVisiblePosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPosition(lastFirstVisiblePosition);
loadMore(count);
}
});

} else {
view = inflater.inflate(R.layout.fragment_connection, container, false);
imageView = (ImageView) view.findViewById(R.id.refresh);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fragmentManager = getActivity().getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
DisplayingFragment fragment = new DisplayingFragment();
fragmentTransaction.replace(R.id.fragments, fragment, DisplayingFragment.class.getName());
fragmentTransaction.commit();
}
});
}
return view;
}

public void updateList(final String dbname) {

String wholeUrl = "http://wwwgyaampe.com/lingme/list.php?table=" + dbname + "&page=1";

necklaceRecyclerAdapter = new NecklaceRecyclerAdapter(getActivity(), listProducts, this);
recyclerView.setAdapter(necklaceRecyclerAdapter);

RequestQueue queue = Volley.newRequestQueue(getActivity());

necklaceRecyclerAdapter.clearAdapter();

showPd();

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, wholeUrl, null, new Response.Listener<jsonobject>() {

@Override
public void onResponse(JSONObject response) {

Log.d("hi", response.toString());
hidePD();

try {
JSONArray results = response.getJSONArray("home");

for (int i = 0; i < results.length(); i++) {

JSONObject post = results.getJSONObject(i);

ListProduct item = new ListProduct();
String img = post.getString("image_path");
System.out.println(img);
item.setImage_path("http://wwwgyaampe.com/img/" + dbname + img);
item.setPrice(Integer.parseInt(post.getString("price")));
item.setName(post.getString("name"));
listProducts.add(item);

}
} catch (Exception e) {
e.printStackTrace();
}
necklaceRecyclerAdapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// VolleyLog.d(TAG, "Error" + error.getMessage());
hidePD();
}
});

queue.add(jsonObjectRequest);
}


public void loadMore(int page) {
String url = "http://wwwgyaampe.com/lingme/list.php?" + "page=" + page + "&table=" + dbname;

necklaceRecyclerAdapter = new NecklaceRecyclerAdapter(getActivity(), listProducts, this);
recyclerView.setAdapter(necklaceRecyclerAdapter);

RequestQueue queue = Volley.newRequestQueue(getActivity());
necklaceRecyclerAdapter.clearAdapter();
showPd();

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<jsonobject>() {

@Override
public void onResponse(JSONObject response) {

hidePD();

try {

JSONArray home = response.getJSONArray("home");
for (int i = 0; i < home.length(); i++) {

JSONObject post = home.getJSONObject(i);

ListProduct h = new ListProduct();
String img = post.getString("image_path");
h.setImage_path("http://wwwgyaampe.com/img/" + dbname + img);
h.setName(post.getString("name"));
h.setId(Integer.parseInt(post.getString("id")));
h.setPrice(Integer.parseInt(post.getString("price")));
h.setDiscout(Integer.parseInt(post.getString("discount")));
listProducts.add(h);


}
} catch (Exception e) {
e.printStackTrace();
}
necklaceRecyclerAdapter.notifyDataSetChanged();
count = count + 1;
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
hidePD();
}
});

queue.add(jsonObjectRequest);
}


public void showPd() {
if (progressDialog == null) {
progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
}
}

public void hidePD() {
if (progressDialog != null) {
progressDialog.dismiss();
progressDialog = null;
}
}

@Override
public void onItemSelected(int itemId) {
Intent in = new Intent(getActivity(), DetailsActivity.class);
in.putExtra("id", listProducts.get(itemId).getId());
in.putExtra("table", dbname);
startActivity(in);
}
}
QuestionRe: why is my fragment not displaying anything Pin
David Crow18-Nov-15 2:52
David Crow18-Nov-15 2:52 
QuestionHow to give path in Android Pin
jasonalien17-Nov-15 1:20
jasonalien17-Nov-15 1:20 
QuestionRe: How to give path in Android Pin
David Crow17-Nov-15 5:16
David Crow17-Nov-15 5:16 
AnswerRe: How to give path in Android Pin
mack %GUI%23-Nov-15 6:04
mack %GUI%23-Nov-15 6:04 
AnswerRe: How to give path in Android Pin
Jervie Ocampo23-Dec-15 8:10
Jervie Ocampo23-Dec-15 8:10 
QuestionInvalid redirected_uri Pin
Deepak Rattan9-Nov-15 19:27
Deepak Rattan9-Nov-15 19:27 
QuestionRe: Invalid redirected_uri Pin
David Crow10-Nov-15 3:11
David Crow10-Nov-15 3:11 
QuestionHow can application like "etude" or "autoflip" work? Pin
Carle_Lai5-Nov-15 16:10
Carle_Lai5-Nov-15 16:10 
AnswerRe: How can application like "etude" or "autoflip" work? Pin
Richard MacCutchan5-Nov-15 23:27
mveRichard MacCutchan5-Nov-15 23:27 
GeneralRe: How can application like "etude" or "autoflip" work? Pin
Carle_Lai6-Nov-15 0:12
Carle_Lai6-Nov-15 0:12 
GeneralRe: How can application like "etude" or "autoflip" work? Pin
Richard MacCutchan6-Nov-15 0:19
mveRichard MacCutchan6-Nov-15 0:19 
GeneralRe: How can application like "etude" or "autoflip" work? Pin
Carle_Lai6-Nov-15 0:37
Carle_Lai6-Nov-15 0:37 
QuestionUpdating multiple cascading spinner by AsyncTask - what would be best approach Pin
Arindam Tewary3-Nov-15 9:06
professionalArindam Tewary3-Nov-15 9:06 
AnswerRe: Updating multiple cascading spinner by AsyncTask - what would be best approach Pin
Richard MacCutchan3-Nov-15 21:59
mveRichard MacCutchan3-Nov-15 21:59 
GeneralRe: Updating multiple cascading spinner by AsyncTask - what would be best approach Pin
Arindam Tewary4-Nov-15 6:59
professionalArindam Tewary4-Nov-15 6:59 
QuestionAndroid app Pin
Member 1118842031-Oct-15 1:00
Member 1118842031-Oct-15 1:00 
AnswerRe: Android app Pin
Richard MacCutchan31-Oct-15 5:12
mveRichard MacCutchan31-Oct-15 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.