Getting the updated array of data from a ListView/Adapter

by Chris Stewart » Wed, 11 Aug 2010 02:45:49 GMT


Sponsored Links
 I must be missing something simple here.  I've searched around but don't
think my search query is touching on the right topics to yield results.
 Anyhow, what I'm after is running through the array of data I bind to a
ListView after a "Submit" button has been clicked.  Here's the sample code
I've found and have hacked up to simplify what I'm after:

private Button btnSubmit;
private List<Map<String,?>> security;
 private SeparatedListAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btnSubmit = (Button)this.findViewById(R.id.btnSubmit);
        btnSubmit.setOnClickListener(new OnClickListener()
        {
         @Override
                public void onClick(View v)
         {
         blah();
         }
        });

        security = new LinkedList<Map<String,?>>();
 security.add(createItem("Remember passwords", "Save usernames and passwords
for Web sites", true));
security.add(createItem("Clear passwords", "Save usernames and passwords for
Web sites", false));
 security.add(createItem("Show security warnings", "Show warning if there is
a problem with a site's security", false));

// create our list and custom adapter
adapter = new SeparatedListAdapter(this);
 adapter.addSection("Security", new SimpleAdapter(
this, security, R.layout.list_complex,
 new String[] { ITEM_TITLE, ITEM_CAPTION, ITEM_CP },
new int[] { R.id.list_complex_title, R.id.list_complex_caption,
R.id.list_complex_cb }
 )
);
 ListView list = (ListView)this.findViewById(R.id.lvList);
list.setAdapter(adapter);
    }

    private void blah()
    {
ListView list = (ListView)this.findViewById(R.id.lvList);
Object obj = list.getItemAtPosition(0);
    }

Regards,
Chris Stewart

Fantasy 
Football< http://chriswstewart.com/android-applications/fantasy-football/> ;-
Android app for fantasy football fanatics and MFL owners
Social Updater< http://chriswstewart.com/android-applications/social-updater/> ;-
An easy way to send your status blast to multiple social networks

--



Getting the updated array of data from a ListView/Adapter

by Kumar Bibek » Wed, 11 Aug 2010 04:27:08 GMT


 Write a method in your adapter that will return all the data.

-Kumar Bibek
 http://techdroid.kbeanie.com 




--


Sponsored Links


Getting the updated array of data from a ListView/Adapter

by Chris Stewart » Wed, 11 Aug 2010 04:44:48 GMT


  was able to get this to work.  Now I'm facing a different issue with the
list recycling and reloading the original data. Anyway, he's the "blah"
method from above that works:

private void blah()
{
int count = adapter.getCount();

ListView lv = (ListView)this.findViewById(R.id.lvList);
//int listItemCount = lv.getChildCount();
for( int i=0;i<count;i++ ) {
View v = (View)lv.getChildAt(i);

if (v != null)
{
CheckBox cbox = (CheckBox) v.findViewById(R.id.list_complex_cb);

if (cbox != null)
{
if (cbox.isChecked())
{
String title =
((TextView)((View)lv.getChildAt(i)).findViewById(R.id.list_complex_title)).getText().toString();
System.out.println("Blah");
}
}
}
}
}
Regards,
Chris Stewart

Fantasy
Football<http://chriswstewart.com/android-applications/fantasy-football/>-
Android app for fantasy football fanatics and MFL owners
Social Updater<http://chriswstewart.com/android-applications/social-updater/>-
An easy way to send your status blast to multiple social networks



On Tue, Aug 10, 2010 at 4:26 PM, Kumar Bibek <coomar....@gmail.com> wrote:

>



Other Threads

1. Avoid restarting background threads on orientation change

> This leads me to a new question....when do I actually destroy the

As soon as their work is done. All else being equal, choose a model where
you do not keep your own threads{*filter*} out forever (e.g., use AsyncTask
rather than forking your own threads).


No, it will not, except by terminating the process, which may not happen
for quite some time after your activity is destroyed. This yet another
reason to use AsyncTask rather than forking your own threads -- threads
*Android* forks *Android* is responsible to clean up.

Moreover, please bear in mind that your activity may be in a stopped state
for an extended period of time (a.k.a., days). Your goal, while stopped,
should be to avoid doing anything much. This is yet another reason to
design your application to avoid forking your own threads that hang around
indefinitely, but rather do your background work in short discrete chunks
in AsyncTasks.


As soon as your work is done.


In your case, if getLastNonConfigurationInstance() is not null, you have
saved state, in the form of the object returned from
getLastNonConfigurationInstance().


Call isFinishing().

-- 
Mark Murphy (a Commons Guy)
 http://www.***.com/ 
Android App Developer Books:  http://www.***.com/ 


-- 

2. How to force Activity to call finalize()?

My application contains 2 activities A and B. B is opened with 
startActivity(intent) in A, when B is closed with finish(), I found the method 
finalize() of B is not called.

My question is:
How to force Activity to call finalize() when it is closed with finish()?

Thanks.



      

-- 

3. OOT apa WTS hari ini bakalan ugal2an

4. Picassa Like Pictures Album Zoom

5. rounded rectangle for TextView

6. Screen lock problem in SurfaceView

7. Issue with WifiManager.calculateSignalLevel(RSSI, 5)