I am trying to populate a listview where each row has 2 textviews and a button. I think I nearly have it working properly but right now the ListView only shows 1 item in the
It is because you inflate the View
when you create the Adapter
. Since you only create the Adapter
once, you only inflate one View
. A View
needs to be inflated for every visible row in your ListView
.
Instead of passing the inflated View
to the constructor of MyListAdapter
:
MyListAdapter adapter = new MyListAdapter(getLayoutInflater().inflate(R.layout.shelfrow,this));
...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = renderer;
}
...
}
Thy this:
// Remove the constructor you created that takes a View.
MyListAdapter adapter = new MyListAdapter();
...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
// Inflate a new View every time a new row requires one.
convertView = LayoutInflater.from(context).inflate(R.layout.shelfrow, parent, false);
}
...
}