1
I have a main class that inherits from Activity where I have my views, but I needed to create another class that inherits Arrayadapter. However I am not able to present my listview, the strange thing is that when you take an item from the list and print it works. Can someone give a help? Thank you in advance!
This method is in my class that inherits Activity. This is the method to fill Activity that is not showing anything.
//recebo um vetor de String com dados do banco
public void preencheListView(String[] paises) {
lv = new ListView(this);
//instancio aqui
adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, paises);
//aqui eu consigo imprimir um pais para teste, o que significa que o adapter está ok
System.out.println("teste: "+adapter.getItem(1));
lv.setAdapter(adapter);
lv.setOnItemClickListener(this);
linearlayout.addView(lv);
}
}
This is my class who inherits Arrayadapter
public class ArrayAdapter extends ArrayAdapter<String> {
public Context ctx;
public int rec;
public String[] paises;
public ArrayAdapter(Context context, int resource, String[] p) {
super(context, android.R.layout.simple_list_item_1, p);
this.ctx = context;
this.rec = resource;
this.paises = p;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return null;
}
public int getRec() {
return rec;
}
public void setRec(int rec) {
this.rec = rec;
}
public Context getCtx() {
return ctx;
}
public void setCtx(Context ctx) {
this.ctx = ctx;
}
public String[] getPaises() {
return paises;
}
public void setPaises(String[] paises) {
this.paises = paises;
}
}
Note: Before I created the class Arrayadapter worked well, but I had to create the Arrayadapter because I will need to use the getView()
.
Note 2: I put one adapter.getCount()
now and found that the Adapter is really empty, but print the item, with the adapter.getItem(x);
Note: I am calling the Arrayadapter class in the correct way?
thank you, it worked perfectly!
– daniel12345smith
Thanks, I’m glad I could help you.
– Eduardo Binotto