0
Good guys, I’ve done this topic~>Listview images and quantity - Android
They gave me some tips and now I’m remaking him like they told me.
I made a custom Adapter for listview.
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;
}
}
This is where I try to wear:
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);
}
}
And this is the 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;
}
The problems:
In custom Adapter
along those lines:
super(context, R.layout.list_picasso, nome);
of the error 'cannot resolve method super(Activit, int, string)'
and in the PicassoTest
:
CustomAdapter adapter = new CustomAdapter(getApplicationContext(), names);
The context
and name does not return, only the image.
How can I fix this?
continues the same error with this modification.
– Marceloawq