@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
rq = Volley.newRequestQueue(MainActivity.this);
callByJsonObjectRequest(null);
}
public void callByJsonObjectRequest(View view){
Log.i("Script", "ENTREI: callByJsonObjectRequest()");
params = new HashMap<String, String>();
params.put("method", "web-data-jor");
CustomJsonObjectRequest request = new CustomJsonObjectRequest(Method.POST,
url,
params,
new Response.Listener<JSONObject>(){
@Override
public void onResponse(JSONObject response) {
Log.i("Script", "SUCCESS: "+ response);
trataJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, "Error: "+ error.getMessage(), Toast.LENGTH_LONG).show();
}
});
request.setTag("tag");
rq.add(request);
}
public void trataJSON(JSONObject response){
JSONArray retorno = null;
try {
retorno = response.getJSONArray("retorno");
} catch (JSONException e) {
e.printStackTrace();
}
// Inicializar arrays com quantidade de objetos contidos em retorno
int t = retorno.length();
nomesProdutos = new String[t];
URLImagens = new String[t];
precosProdutos = new String[t];
locaisProdutos = new String[t];
datasProdutos = new String[t];
// looping para pegar todas as linhas
for (int i = 0; i < retorno.length(); i++) {
try {
JSONObject r = retorno.getJSONObject(i);
nomesProdutos[i] = r.getString("produto");
URLImagens[i] = "url" + i;
precosProdutos[i] = r.getString("preco");
locaisProdutos[i] = r.getString("estabelecimento");
datasProdutos[i] = "21/05/2015" ;
} catch (JSONException e) {
e.printStackTrace();
}
}
setListaPrincipal();
}
private void setListaPrincipal() {
// Adapter list
rowItems = new ArrayList<RowItem>();
for (int i = 0; i < nomesProdutos.length; i++) {
RowItem item = new RowItem(nomesProdutos[i],
R.drawable.ic_launcher, precosProdutos[i],
locaisProdutos[i], datasProdutos[i]);
rowItems.add(item);
}
mylistview = (ListView) findViewById(R.id.listaPrincipal);
CustomAdapterLista adapter = new CustomAdapterLista(this, rowItems);
mylistview.setAdapter(adapter);
// imagensProdutos.recycle();
//mylistview.setOnItemClickListener((OnItemClickListener) this);
}
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.






0 comentários:
Postar um comentário