Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

marcosklein

Android JAVA - Consultar BD online

Recommended Posts

E ai galera!

Primeiro post aqui, sou iniciante em desenvolvimento android.
Estou criando aqui um aplicativo que consulta e adiciona dados apenas em uma base de dados on-line no Hostinger.

Em uma activity adiciona ( funciona NORMAL ), em outra acitivity Lê TODAS as entradas da BD num List View(Funciona normal), o PROBLEMA é quando clico no listitem para ver o detalhamento, em outra activity, era para aparecer a id e todos os campos em TextView's, porém só aparece a ID, que vem do 'putextra' do intent anterior, não aparecem os dados!

Sabem o porquê de não estar aparecendo na activity os dados? icon_cry.gif
Acho que como o PHP está funcionando corretamente, e o id está sendo guardado para a outra activity o erro deve estar no código da activity do detalhamento

OBS: os arquivos php estão corretos, os links para tais arquivos também estão corretos.
OBS2: Códigos abaixo.


Obrigado já adiantado!

CÓDIGO DA ACTIVITY QUE MOSTRA O LISTVIEW COM TODAS AS ENTRADAS
package com.ufrj.marcosk.queroic;


import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

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

import java.util.ArrayList;
import java.util.HashMap;

/**
* Created by MarcosK on 03/03/2016.
*/

public class viewvagas extends AppCompatActivity implements ListView.OnItemClickListener {

private ListView listView;

private String JSON_STRING;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewvagas);
listView = (ListView) findViewById(R.id.lv);
listView.setOnItemClickListener(this);
getJSON();

EditText filtro = (EditText)findViewById(R.id.edtText);

}

private void showVagas(){
JSONObject jsonObject = null;
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
try {
jsonObject = new JSONObject(JSON_STRING);
JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);

for(int i = 0; i<result.length(); i++){
JSONObject jo = result.getJSONObject(i);
String id = jo.getString(Config.TAG_ID);
String titulo = jo.getString(Config.TAG_titulo);
String area = jo.getString(Config.TAG_area);
HashMap<String,String> vagas = new HashMap<>();
vagas.put(Config.TAG_ID, id);
vagas.put(Config.TAG_area,area);
vagas.put(Config.TAG_titulo,titulo);
list.add(vagas);
}

} catch (JSONException e) {
e.printStackTrace();
}

final ListAdapter adapter = new SimpleAdapter(
viewvagas.this, list, R.layout.list_item,
new String[]{Config.TAG_ID,Config.TAG_area,Config.TAG_titulo},
new int[]{R.id.id1,R.id.area1, R.id.titulo1});

listView.setAdapter(adapter);



}


private void getJSON(){
class GetJSON extends AsyncTask<Void,Void,String> {

ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(viewvagas.this,"Carregando Vagas","Aguarde...",false,false);
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
JSON_STRING = s;
showVagas();
}

@Override
protected String doInBackground(Void... params) {
RequestHandler rh = new RequestHandler();
String s = rh.sendGetRequest(Config.URL_GET_ALL);
return s;
}
}
GetJSON gj = new GetJSON();
gj.execute();
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(this, ViewVaga.class);
HashMap<String,String> map =(HashMap)parent.getItemAtPosition(position);
String empId = map.get(Config.TAG_ID).toString();
intent.putExtra(Config.VG_ID,empId);
startActivity(intent);
}

}


CÓDIGO DA ACTIVITY QUE VE O DETALHAMENTO DE CADA DADO

package com.ufrj.marcosk.queroic;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;

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

public class ViewVaga extends Activity {
private String id;

private TextView tvid;
private TextView tvtitulo;
private TextView tvarea;
private TextView tvch;
private TextView tvcurso;
private TextView tvperiodo;
private TextView tvmats;
private TextView tvdesvaga;
private TextView tvvb;
private TextView tvorientador;
private TextView tvemail;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewvaga);

Intent intent = getIntent();

id = intent.getStringExtra(Config.VG_ID);

tvid = (TextView) findViewById(R.id.viewid);
tvtitulo = (TextView) findViewById(R.id.viewtitulo);
tvarea = (TextView) findViewById(R.id.viewarea);
tvch = (TextView) findViewById(R.id.viewch);
tvcurso = (TextView) findViewById(R.id.viewcurso);
tvperiodo = (TextView) findViewById(R.id.viewperiodo);
tvmats = (TextView) findViewById(R.id.viewmats);
tvdesvaga = (TextView) findViewById(R.id.viewdesvaga);
tvvb = (TextView) findViewById(R.id.viewvb);
tvorientador = (TextView) findViewById(R.id.vieworientador);
tvemail = (TextView) findViewById(R.id.viewemail);

tvid.setText(id);

getVaga();

}
private void getVaga(){
class GetVaga extends AsyncTask<Void,Void,String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(ViewVaga.this,"Carregando...","Aguarde...",false,false);
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
showVaga(s);
}

@Override
protected String doInBackground(Void... params) {
RequestHandler rh = new RequestHandler();
String s = rh.sendGetRequestParam(Config.URL_GET_EMP,id);
return s;
}
}
GetVaga gv = new GetVaga();
gv.execute();
}

private void showVaga(String json){
try {
JSONObject jsonObject = new JSONObject(json);
JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);
JSONObject c = result.getJSONObject(0);
String titulo = c.getString(Config.TAG_titulo);
String area = c.getString(Config.TAG_area);
String ch = c.getString(Config.TAG_ch);
String curso = c.getString(Config.TAG_curso);
String periodo = c.getString(Config.TAG_periodo);
String mats = c.getString(Config.TAG_mats);
String des = c.getString(Config.TAG_des);
String bolsa = c.getString(Config.TAG_bolsa);
String orientador = c.getString(Config.TAG_orientador);
String email = c.getString(Config.TAG_email);

tvtitulo.setText(titulo);
tvarea.setText(area);
tvch.setText(ch);
tvcurso.setText(curso);
tvperiodo.setText(periodo);
tvmats.setText(mats);
tvdesvaga.setText(des);
tvvb.setText(bolsa);
tvorientador.setText(orientador);
tvemail.setText(email);

} catch (JSONException e) {
e.printStackTrace();
}
}

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.