Well guys, I already did this topic ~ > Image and Quantity Listview - Android
They gave me some tips and now I'm redoing it as they told me.
I made a custom adapter for the 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;
}
}
Here's where I try to use:
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
on this line:
super(context, R.layout.list_picasso, nome);
Give the error 'can not solve super method (Activit, int, string)'
and PicassoTest
:
CustomAdapter adapter = new CustomAdapter(getApplicationContext(), names);
The context
and name does not return, just the image.
How can I resolve this?