Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ArrayList<Aluno> buscarTodosUsuarios() {
- ArrayList<Aluno> lista = new ArrayList<Aluno>();
- try {
- Connection conn = ConectaMySql.obtemConexao();
- String queryInserir = "SELECT * FROM ALUNO ORDER BY NOME";
- PreparedStatement ppStm = conn.prepareStatement(queryInserir);
- ResultSet rSet = ppStm.executeQuery();
- while (rSet.next()) {
- Aluno user = new Aluno();
- user.setId(rSet.getInt(1));
- user.setNome(rSet.getString(2));
- user.setLogin(rSet.getString(3));
- user.setPass(rSet.getString(4));
- user.setCurso(rSet.getString(5));
- user.setSegunda(rSet.getString(6));
- user.setM1(rSet.getString(7));
- user.setTerca(rSet.getString(8));
- user.setM2(rSet.getString(9));
- user.setQuarta(rSet.getString(10));
- user.setM3(rSet.getString(11));
- user.setQuinta(rSet.getString(12));
- user.setM4(rSet.getString(13));
- user.setSexta(rSet.getString(14));
- user.setM5(rSet.getString(15));
- user.setFoto(rSet.getBytes(16));
- lista.add(user);
- }
- conn.close();
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- return lista;
- }
- public List<Aluno> buscarTodosUsuarios() {
- List<Aluno> listaUsr = new ArrayList<Aluno>();
- SoapObject buscarUsuarios = new SoapObject(NAMESPACE, BUSCAR_TODOS);
- SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
- SoapEnvelope.VER11);
- envelope.setOutputSoapObject(buscarUsuarios);
- envelope.implicitTypes = true;
- HttpTransportSE http = new HttpTransportSE(URL);
- try {
- http.call("urn:" + BUSCAR_TODOS, envelope);
- if (envelope.getResponse() instanceof SoapObject) {
- SoapObject resposta = (SoapObject) envelope.getResponse();
- Aluno usr = new Aluno();
- usr.setId(Integer.parseInt(resposta.getProperty("id")
- .toString()));
- usr.setNome(resposta.getProperty("nome").toString());
- usr.setCurso(resposta.getProperty("curso").toString());
- usr.setSegunda(resposta.getProperty("segunda").toString());
- usr.setM1(resposta.getProperty("m1").toString());
- usr.setTerca(resposta.getProperty("terca").toString());
- usr.setM2(resposta.getProperty("m2").toString());
- usr.setQuarta(resposta.getProperty("quarta").toString());
- usr.setM3(resposta.getProperty("m3").toString());
- usr.setQuinta(resposta.getProperty("quinta").toString());
- usr.setM4(resposta.getProperty("m4").toString());
- usr.setSexta(resposta.getProperty("sexta").toString());
- usr.setM5(resposta.getProperty("m5").toString());
- String foto = resposta.getProperty("foto").toString();
- usr.setTesteFoto(foto.toString());
- byte[] bt = Base64.decode(foto, Base64.DEFAULT);
- usr.setFoto(bt);
- listaUsr.add(usr);
- } else {
- Vector<SoapObject> retorno = (Vector<SoapObject>) envelope
- .getResponse();
- for (SoapObject resposta : retorno) {
- Aluno usr = new Aluno();
- usr.setId(Integer.parseInt(resposta.getProperty("id")
- .toString()));
- usr.setNome(resposta.getProperty("nome").toString());
- usr.setCurso(resposta.getProperty("curso").toString());
- usr.setSegunda(resposta.getProperty("segunda").toString());
- usr.setM1(resposta.getProperty("m1").toString());
- usr.setTerca(resposta.getProperty("terca").toString());
- usr.setM2(resposta.getProperty("m2").toString());
- usr.setQuarta(resposta.getProperty("quarta").toString());
- usr.setM3(resposta.getProperty("m3").toString());
- usr.setQuinta(resposta.getProperty("quinta").toString());
- usr.setM4(resposta.getProperty("m4").toString());
- usr.setSexta(resposta.getProperty("sexta").toString());
- usr.setM5(resposta.getProperty("m5").toString());
- String foto = resposta.getProperty("foto").toString();
- usr.setTesteFoto(foto.toString());
- byte[] bt = Base64.decode(foto, Base64.DEFAULT);
- usr.setFoto(bt);
- listaUsr.add(usr);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- return listaUsr;
- }
- public class ListarTodosActivity extends Activity {
- private ListView lvUsuario;
- private List<Aluno> usrs;
- private AlunoDAO dao;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_listartodos);
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
- .permitAll().build();
- StrictMode.setThreadPolicy(policy);
- dao = new AlunoDAO();
- lvUsuario = (ListView) findViewById(R.id.lvListarTodos);
- usrs = dao.buscarTodosUsuarios();
- AlunoAdapter usrAdp = new AlunoAdapter(this, usrs);
- lvUsuario.setAdapter(usrAdp);
- lvUsuario.setOnItemClickListener(new OnItemClickListener() {
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- Aluno aluno = (Aluno) lvUsuario.getItemAtPosition(position);
- Intent intent = new Intent(ListarTodosActivity.this,
- DetalhesActivity.class);
- intent.putExtra("ALUNO_NOME", aluno.getNome().toString());
- intent.putExtra("ALUNO_CURSO", aluno.getCurso().toString());
- intent.putExtra("ALUNO_FOTO", aluno.getTesteFoto().toString());// envio
- // a
- // string
- // da
- // foto
- // do
- // banco
- // para
- // meu
- // detalhesActivity.class
- intent.putExtra("ALUNO_DIA1", aluno.getSegunda().toString());
- intent.putExtra("ALUNO_M1", aluno.getM1().toString());
- intent.putExtra("ALUNO_DIA2", aluno.getTerca().toString());
- intent.putExtra("ALUNO_M2", aluno.getM2().toString());
- intent.putExtra("ALUNO_DIA3", aluno.getQuarta().toString());
- intent.putExtra("ALUNO_M3", aluno.getM3().toString());
- intent.putExtra("ALUNO_DIA4", aluno.getQuinta().toString());
- intent.putExtra("ALUNO_M4", aluno.getM4().toString());
- intent.putExtra("ALUNO_DIA5", aluno.getSexta().toString());
- intent.putExtra("ALUNO_M5", aluno.getM5().toString());
- startActivity(intent);
- }
- });
- }
- public class AlunoAdapter extends BaseAdapter {
- private List<Aluno> usrs;
- private Context context;
- public AlunoAdapter(Context context, List<Aluno> usrs) {
- this.usrs = usrs;
- this.context = context;
- }
- @Override
- public int getCount() {
- return usrs.size();
- }
- @Override
- public Object getItem(int arg0) {
- return usrs.get(arg0);
- }
- @Override
- public long getItemId(int arg0) {
- return usrs.get(arg0).getId();
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View rootView = LayoutInflater.from(context).inflate(
- R.layout.activity_modelo_aluno, parent, false);
- ImageView imgFoto = (ImageView) rootView.findViewById(R.id.imgFoto);
- TextView txtNome = (TextView) rootView.findViewById(R.id.txtNome);
- TextView txtCurso = (TextView) rootView.findViewById(R.id.txtCurso);
- Aluno usuarioDaVez = usrs.get(position);
- txtNome.setText(usuarioDaVez.getNome());
- txtCurso.setText(usuarioDaVez.getCurso());
- Bitmap bitmap = BitmapFactory.decodeByteArray(usuarioDaVez.getFoto(),
- 0, usuarioDaVez.getFoto().length);
- imgFoto.setImageBitmap(bitmap);
- return rootView;
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement