Reputation: 777
I want dynamically fill listview with List It is my code:
ListView lis;
List<String> values=new ArrayList<String>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_pages, container, false);
values.add("a1");
values.add("a2");
values.add("a3");
values.add("a4");
values.add("a5");
values.add("a6");
values.add("a7");
values.add("a8");
values.add("a9");
values.add("a10");
values.add("a11");
lis =(ListView)rootView.findViewById(R.id.listView1);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_list_item_1,values );
lis.setAdapter(arrayAdapter);
lis.setOnScrollListener(new OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState)
{
int first = view.getFirstVisiblePosition();
int count = view.getChildCount();
if (scrollState == SCROLL_STATE_IDLE || (first + count > arrayAdapter.getCount()) ) {
fill_list();
}
}
public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount)
{
}
});
return rootView;
}
public void fill_list()
{
for (int i = 0; i < 10; i++)
{
values.add("b "+ i);
}
but it dosent work,my list is fill but Listview dosent fill.
Upvotes: 0
Views: 252
Reputation: 621
First, remember to call list.notifyDataSetChanged();
when you want to update listView content.
Also for this case I recommend you use a custom Adapter and implement your methods manually so you con override notifyDataSetChanged() method, maybe something like:
public class MyAdapter entends BaseAdapter{
//Stuff...
public void notifyDataSetChanged(){
fillList();
super.notifyDataSetChanged();
}
}
Hope this helps, sorry for my pseudocode.
Best regards.
Upvotes: 1