listView with image text and subtitle

2

I'm setting up a sales app where a user will publish your product with price description and value description, I can list the photo all right but I can not put a title and the other descriptions

Here is my list and my adapter

public class OfertasAdapter extends ArrayAdapter<ParseObject> {
    private Context context;
    private ArrayList<ParseObject> publicacoes;

    public OfertasAdapter(Context c, ArrayList<ParseObject> objects) {
        super(c, 0, objects);
        this.context = c;
        this.publicacoes = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;

        if (view == null) {

            //Inicializa objeto para montagem do layout
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);

            //Monta a view a partir do xml
            view = inflater.inflate(R.layout.lista_publicacoes, parent, false);
        }
            //Verifica se existe postagens
        if (publicacoes.size() > 0) {

            //Recupera componentes da tela
            ImageView imagemPostagem = (ImageView) view.findViewById(R.id.image_lista_publicacoes);

            ParseObject parseObject = publicacoes.get(position);

            //parseObject.getParseFile( "imagem" );
            Picasso.with(context)
            .load( parseObject.getParseFile( "imagem" ).getUrl() )
            .fit()
            .into( imagemPostagem );


         }


        return view;
    }

}

this is the process of saving the image to the database

public class PublicarOfertasActivity extends AppCompatActivity {
    private ImageView botaoPublicar;
    private ViewPager viewPager;
    private Button botaoPublicar2;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_publicar_ofertas);
        botaoPublicar = (ImageView) findViewById(R.id.imagePublicar);
        viewPager = (ViewPager) findViewById(R.id.view_pager_main);
        /*configurar adapter novo
        TabsAdapter  tabsAdapter = new TabsAdapter(getSupportFragmentManager(),this);
        viewPager.setAdapter(tabsAdapter);*/




        botaoPublicar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                publicarOfertas();
            }
        });
    }

    private void publicarOfertas() {

        Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(intent, 1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        //testar o processo de retorno dos dados
        if (requestCode == 1 && resultCode == RESULT_OK && data != null) {


            //Recuperar local do recurso
            Uri localImagemSelecionada = data.getData();



            //Recupera a imagem do local que foi selecionada
            try {
                Bitmap imagem = MediaStore.Images.Media.getBitmap(getContentResolver(), localImagemSelecionada);

                /*
                Comprimir imagem no formato PNG
                 */
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                imagem.compress(Bitmap.CompressFormat.PNG, 75, stream);

                /*Comprimir imagem no formato JPG!!!
                */
                ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                imagem.compress(Bitmap.CompressFormat.JPEG, 75, stream2);

                /*Cria 2 Arrays de Bytes da imagem tanto PNG quanto JPEG
                */
                byte[] byteArray = stream.toByteArray();
                byte[] byteArray2 = stream2.toByteArray();

                /*Cria arquivos com formato proprio do Parse para PNG e JPEG
                 */
                SimpleDateFormat dateFormat = new SimpleDateFormat("ddmmaaaahhmmss");
                String nomeImagem = dateFormat.format(new Date());
                ParseFile arquivoParse = new ParseFile(nomeImagem + "imagem.png", byteArray);
                ParseFile arquivoParse2 = new ParseFile(nomeImagem + "imagem.jpeg", byteArray2);

                /*Monta um objeto para salvar no Parse
                 */
                ParseObject parseObject = new ParseObject("Imagem");
                parseObject.put("username", ParseUser.getCurrentUser().getUsername());

                /*Atribui 2 entradas de dados no objeto "imagem", para PNG e JPEG
                 */
                parseObject.put("imagem", arquivoParse);
                parseObject.put("imagem", arquivoParse2);




                //Salvar os dados
                parseObject.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {

                        if (e == null) {//Sucesso
                            Toast.makeText(getApplicationContext(), "Sua imagem foi postada!", Toast.LENGTH_LONG).show();
                           /* TabsAdapter adapterNovo = (TabsAdapter) viewPager.getAdapter();
                            OfertasDoDia ofertasDoDiaNovo =(OfertasDoDia) adapterNovo.getFragment(1);
                            ofertasDoDiaNovo.atualizaPublicacoes();*/

                        } else {//Erro
                            Toast.makeText(getApplicationContext(), "Erro ao postar sua imagem, tente novamente!",
                                    Toast.LENGTH_LONG).show();
                        }


                    }


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


        }

    }

and here I've ready the images in the fragment

public class OfertasDoDia extends Fragment {
    private ArrayList<ParseObject> publicacoes;
    private ListView listView;
    private ArrayAdapter<ParseObject> adapter;
    private ParseQuery<ParseObject> recuperaImagem;



    public OfertasDoDia() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
       View view = inflater.inflate(R.layout.fragment_ofertas_do_dia, container, false);

        //montar listview e adapter

        publicacoes = new ArrayList<>();
        listView = (ListView) view.findViewById(R.id.list_publicacoes);
        adapter= new OfertasAdapter(getActivity(),publicacoes);
        listView.setAdapter(adapter);

        //recupera postagens
        getPublicacoes();

        return view;
    }
    private void getPublicacoes(){
            recuperaImagem = ParseQuery.getQuery("Imagem");


       // query.whereEqualTo( "username", ParseUser.getCurrentUser().getUsername() );
        recuperaImagem.orderByDescending("createdAt");
        recuperaImagem.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> objects, ParseException e) {

                if ( e == null ){//Sucesso

                    if ( objects.size() > 0 ){
                        publicacoes.clear();
                        for ( ParseObject parseObject : objects ){
                            publicacoes.add( parseObject );
                        }
                        adapter.notifyDataSetChanged();
                    }

                }else{//Erro
                    e.printStackTrace();

                }
            }
        });

    }
    
asked by anonymous 12.01.2017 / 00:52

1 answer

0

To load image and text into a custom ListView, there is nothing better than the LazyAdapter. You may need to redo some of the code, but it's worth it.

This question in the English Stack is quite complete with example . It also has a complete whole for you here on GitHub

Ah, if you are storing the images in the bank, do not do this, ever! Instead, save the link to the folder where the image is located and retrieve it with your preferred language [PHP :)], and return everything (images and text) in the JSON format of the database through a page on the server.

(Read about PHP WebService)

    
05.02.2017 / 00:41