Setting the Image String on an Android Imagebutton

Asked

Viewed 101 times

0

I have an Imageview and the path of an image in a String, as I can set in Imageview the path of the image since they are of different types ?

public TemaArrayAdapter buscaTema(Context context)
    {

        TemaArrayAdapter adpTema = new TemaArrayAdapter(context, R.layout.tema_item );

        Cursor cursor  =  conn.rawQuery("Select t.NomeTema, i.ArqImagem, s.ArqSom from Grude g " +
                                        "inner join Tema t on g.CodTema = t.CodTema " +
                                        "inner join Imagem i on g.CodImagem = i.CodImagem " +
                                        "inner join Som s on g.CodSom = s.CodSom", null);

        if (cursor.getCount() > 0 )
        {

            cursor.moveToFirst();

            do {


                Classe_Junta j = new Classe_Junta();   
                j.setNomeTema(cursor.getString(cursor.getColumnIndex(Classe_Tema.NomeTema)));
                j.setArquivoImagem(cursor.getString(cursor.getColumnIndex(Classe_Imagem.ArqImagem)));  //aqui é o caminho da imagem que esta no Classe_Imagem.ArqImagem
                j.setArquivoSom( cursor.getString(cursor.getColumnIndex(Classe_Som.ArqSom ) ) );



                adpTema.add(j);

            }while (cursor.moveToNext());

        }

        return adpTema;

    }

public class TemaArrayAdapter extends ArrayAdapter<Classe_Junta> {
    private int resource = 0;
    private LayoutInflater inflater;
    private Context context;

    public TemaArrayAdapter(Context context, int resource)
    {
        super(context, resource);
        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.resource = resource;
        this.context = context;
    }

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

        View view = null;
        ViewHolder viewHolder = null;

        if (convertView == null)
        {
            viewHolder = new ViewHolder();

            view = inflater.inflate(resource, parent, false);

            viewHolder.txtArqSom = (TextView)view.findViewById(R.id.txtSom);
            viewHolder.txtNomeTema = (TextView)view.findViewById(R.id.txtNomeTema);
            viewHolder.imgTema = (ImageView) view.findViewById(R.id.imgTema);


            view.setTag(viewHolder);

            convertView = view;

        }
        else
        {
            viewHolder = (ViewHolder)convertView.getTag();
            view = convertView;
        }

        Classe_Junta j = getItem(position);

        viewHolder.txtArqSom.setText(j.getArquivoSom());
        //viewHolder.imgTema.(j.getArquivoimagem()); (Aqui que esta o problema, como faço para setar no imgTema que é o tipo ImageView a String do caminho da imagem do j.getArquivoImagem(); )
        viewHolder.txtNomeTema.setText(j.getNomeTema());

        return view;

    }

    static class ViewHolder
    {

        TextView txtNomeTema;
        ImageView imgTema;
        TextView txtArqSom;


    }

}

  • See if you can explain better what you want to ask. I can’t understand what you mean by "set in the Imagebutton"

  • I’m sorry I put Imagebutton but it’s Imageview, but then I have Imageview and String from the image path an image of any kind, when I enter the screen where Imageview, I wanted with that image path to appear in Imageview

  • You want the Imageview, instead of an image, display the text in the String?

  • I want it to show the image even there in Imageview, to load the image that is in the image path

  • See if this reply help you. There change Imagebutton for Imageview

  • I edited the question with the code, I did not understand very well the answer you recommended me, but see if this more clarifying my question, thanks :)

  • 1

    Look at this reply.

  • Thank you very much, solved my problem :)

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.