I have a main class that inherits from Activity where I have my views, but I needed to create another class that inherits ArrayAdapter. But I'm 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 populate the activity that is not displaying 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 that 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;
}
}
Obs2: I put a getView()
now and found that the adapter is empty even though I print the item with adapter.getCount()
Obs3: I'm calling the ArrayAdapter class the right way?