Hello, Kumar!
I have a problem when I try to add items to my custom adapter.
Everytime when i add new item to adapter
for(int i=0;i<m_orders.size();i++)
m_adapter.add(m_orders.get(i));
the size of m_orders (ArrayList joined to ListAdapter) also increase
and application hangs.
For example, i add to m_oders 20 items i need to display, than i must
add this items to adapter. Everytime when I add new item to adapter,
size of m_orders becomes 21, 22, 23, ... I don't understand why.
If i don't add items to adapter, i have empty listview.
I hope i explain my problem :)
Much appreciate for your time, Kumar :)))
On 19 Бер, 20:06, Kumar Bibek <[email protected]> wrote:
> What errors or problem do you get?
>
> Thanks and Regards,
> Kumar Bibek
>
> On Mar 19, 8:07 pm, Tatyana Ulyanova <[email protected]> wrote:
>
> > Hello, friends!
>
> > I have a problem with adding new items to ListView.
>
> > I use custom adapter MyListAdapter. I do that way:
>
> > public class MyView extends ListActivity{
>
> > private ArrayList<Order> m_orders = null;
> > privateMyListAdapter m_adapter;
> > private Runnable viewOrders;
>
> > @Override
> > public void onCreate(Bundle savedInstanceState) {
> > super.onCreate(savedInstanceState);
> > setContentView(R.layout.main);
> > m_orders = new ArrayList<Order>();
> > this.m_adapter = new OrderAdapter(this, R.layout.row,
> > m_orders);
> > setListAdapter(this.m_adapter);
>
> > viewOrders = new Runnable(){
> > @Override
> > public void run() {
> > getOrders();
> > }
> > };
> > Thread thread = new Thread(null, viewOrders,
> > "MagentoBackground");
> > thread.start();
> > m_ProgressDialog = ProgressDialog.show(MyView.this,
> > "Please wait...", "Retrieving data ...", true);
> > }
> > private Runnable returnRes = new Runnable() {
>
> > @Override
> > public void run() {
> > if(m_orders != null && m_orders.size() > 0){
> > m_adapter.notifyDataSetChanged();
> > for(int i=0;i<m_orders.size();i++)
> > m_adapter.add(m_orders.get(i));
> > }
> > m_adapter.notifyDataSetChanged();
> > }
> > };
>
> > private void getOrders(){
> > try{
> > m_orders.addAll(/*some order collection*/)
> > runOnUiThread(returnRes);
> > }
>
> > private class OrderAdapter extends ArrayAdapter<Order> {
> > //code about how to get view
>
> > }
> > }
>
> > But when I add items to my adapter:
> > for(int i=0;i<m_orders.size();i++)
> > m_adapter.add(m_orders.get(i));
> > the application hangs because of m_orders increase there size,
> > everytime where new item adds to adapter.
>
> > Friends, do you have any ideas how to implement dynamically adding
> > items to custom ListAdapter? Do you see any errors in my code?
>
> > Thank you very much :)))
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe from this group, send email to
android-developers+unsubscribegooglegroups.com or reply to this email with the
words "REMOVE ME" as the subject.