Skip to main content
replaced http://pt.stackoverflow.com/ with https://pt.stackoverflow.com/
Fonte Link

Bom galera, já fiz esse tópico~>httptópico~>https://pt.stackoverflow.com/questions/180096/listview-de-imagens-e-quantidade-android/180100?noredirect=1#comment372859_180100

Bom galera, já fiz esse tópico~>http://pt.stackoverflow.com/questions/180096/listview-de-imagens-e-quantidade-android/180100?noredirect=1#comment372859_180100

Bom galera, já fiz esse tópico~>https://pt.stackoverflow.com/questions/180096/listview-de-imagens-e-quantidade-android/180100?noredirect=1#comment372859_180100

adicionou 127 caracteres ao conteúdo
Fonte Link
rsicarelli
  • 3,1mil
  • 12
  • 26

public class CustomAdapter extends ArrayAdapter {

public class CustomAdapter extends ArrayAdapter<String> {

    private final Activity context;
    private final String nome;
    private final Integer imagem;
 

    public CustomAdapter(Activity context, String nome, Integer imagem)
  {
        super(context, R.layout.list_picasso, nome);
        this.context = context;
        this.nome = nome;
        this.imagem = imagem;
    }

    public View getView(int position, View view, ViewGroup parent) {
        LayoutInflater inflater = context.getLayoutInflater();
        View rowView=inflater.inflate(R.layout.list_picasso, null,true);

        TextView txtTitle = (TextView) rowView.findViewById(R.id.nome);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.imagem);

        txtTitle.setText(nome);
        Picasso.with(getContext())
            .load(imagem)
            .into(imageView);
        
        return rowView;
    }
}

public class PicassoTest extends AppCompatActivity {

public class PicassoTest extends AppCompatActivity {

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

        DatabaseAccess.getInstance(getApplicationContext()).open();
        List<String> names = DatabaseAccess.getInstance(getApplicationContext()).getTest();
        DatabaseAccess.getInstance(getApplicationContext()).close();

        ListView listView1 = (ListView)findViewById(R.id.Lista);

        CustomAdapter adapter =  new CustomAdapter(getApplicationContext(), names)
        listView1.setAdapter(adapter);
 
    }
}

Os problemas: No custom Adapter nessaAdapter nessa linha:

da o erro 'cannot 'cannot resolve method super(Activit, int, string)'

e na PicassoTestPicassoTest:

        CustomAdapter adapter =  new CustomAdapter(getApplicationContext(), names);

O contextcontext e nome não retorna, só a imagem.

public class CustomAdapter extends ArrayAdapter {

private final Activity context;
private final String nome;
private final Integer imagem;
 

public CustomAdapter(Activity context, String nome, Integer imagem)
 {
    super(context, R.layout.list_picasso, nome);
    this.context = context;
    this.nome = nome;
    this.imagem = imagem;
}

public View getView(int position, View view, ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();
    View rowView=inflater.inflate(R.layout.list_picasso, null,true);

    TextView txtTitle = (TextView) rowView.findViewById(R.id.nome);
    ImageView imageView = (ImageView) rowView.findViewById(R.id.imagem);

    txtTitle.setText(nome);
    Picasso.with(getContext())
        .load(imagem)
        .into(imageView);
    
    return rowView;

}

public class PicassoTest extends AppCompatActivity {

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

    DatabaseAccess.getInstance(getApplicationContext()).open();
    List<String> names = DatabaseAccess.getInstance(getApplicationContext()).getTest();
    DatabaseAccess.getInstance(getApplicationContext()).close();

    ListView listView1 = (ListView)findViewById(R.id.Lista);

    CustomAdapter adapter =  new CustomAdapter(getApplicationContext(), names)
    listView1.setAdapter(adapter);
 

}

Os problemas: No custom Adapter nessa linha

da o erro 'cannot resolve method super(Activit, int, string)'

e na PicassoTest

        CustomAdapter adapter =  new CustomAdapter(getApplicationContext(), names);

O context e nome não retorna, só a imagem.

public class CustomAdapter extends ArrayAdapter<String> {

    private final Activity context;
    private final String nome;
    private final Integer imagem;

    public CustomAdapter(Activity context, String nome, Integer imagem) {
        super(context, R.layout.list_picasso, nome);
        this.context = context;
        this.nome = nome;
        this.imagem = imagem;
    }

    public View getView(int position, View view, ViewGroup parent) {
        LayoutInflater inflater = context.getLayoutInflater();
        View rowView=inflater.inflate(R.layout.list_picasso, null,true);

        TextView txtTitle = (TextView) rowView.findViewById(R.id.nome);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.imagem);

        txtTitle.setText(nome);
        Picasso.with(getContext())
            .load(imagem)
            .into(imageView);
        
        return rowView;
    }
}
public class PicassoTest extends AppCompatActivity {

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

        DatabaseAccess.getInstance(getApplicationContext()).open();
        List<String> names = DatabaseAccess.getInstance(getApplicationContext()).getTest();
        DatabaseAccess.getInstance(getApplicationContext()).close();

        ListView listView1 = (ListView)findViewById(R.id.Lista);

        CustomAdapter adapter =  new CustomAdapter(getApplicationContext(), names)
        listView1.setAdapter(adapter);
    }
}

Os problemas: No custom Adapter nessa linha:

da o erro 'cannot resolve method super(Activit, int, string)'

e na PicassoTest:

CustomAdapter adapter =  new CustomAdapter(getApplicationContext(), names);

O context e nome não retorna, só a imagem.

Fonte Link
Marceloawq
  • 994
  • 7
  • 27

Custom Listview com Picasso

Bom galera, já fiz esse tópico~>http://pt.stackoverflow.com/questions/180096/listview-de-imagens-e-quantidade-android/180100?noredirect=1#comment372859_180100

Me deram algumas dicas e agora tô refazendo ele como me falaram.

Fiz um custom adapter para o listview.

public class CustomAdapter extends ArrayAdapter {

private final Activity context;
private final String nome;
private final Integer imagem;


public CustomAdapter(Activity context, String nome, Integer imagem)
{
    super(context, R.layout.list_picasso, nome);
    this.context = context;
    this.nome = nome;
    this.imagem = imagem;
}

public View getView(int position, View view, ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();
    View rowView=inflater.inflate(R.layout.list_picasso, null,true);

    TextView txtTitle = (TextView) rowView.findViewById(R.id.nome);
    ImageView imageView = (ImageView) rowView.findViewById(R.id.imagem);

    txtTitle.setText(nome);
    Picasso.with(getContext())
        .load(imagem)
        .into(imageView);
    
    return rowView;

}

Aqui é onde tento usar:

public class PicassoTest extends AppCompatActivity {

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

    DatabaseAccess.getInstance(getApplicationContext()).open();
    List<String> names = DatabaseAccess.getInstance(getApplicationContext()).getTest();
    DatabaseAccess.getInstance(getApplicationContext()).close();

    ListView listView1 = (ListView)findViewById(R.id.Lista);

    CustomAdapter adapter =  new CustomAdapter(getApplicationContext(), names)
    listView1.setAdapter(adapter);


}

E essa é a query:

public List<String> getTest() {
    List<String> list = new ArrayList<>();
    Cursor cursor = database.rawQuery("SELECT nome, imagem FROM skin", null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        list.add(cursor.getString(0));
        list.add(cursor.getString(1));
        cursor.moveToNext();
    }
    cursor.close();
    return list;
}

Os problemas: No custom Adapter nessa linha

super(context, R.layout.list_picasso, nome);

da o erro 'cannot resolve method super(Activit, int, string)'

e na PicassoTest

        CustomAdapter adapter =  new CustomAdapter(getApplicationContext(), names);

O context e nome não retorna, só a imagem.

Como posso resolver isso?