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. how to use android-2.3.3_r1 for development

dear all,
I've been developing android application using NFC technology. On SDK,
android 2.3.3 api 10, package android.nfc class NfcAdapter i can not
find method getLocalNdefMessage. I see this method on android source
release branch android-2.3.3_r1. My question is how to use it for
development, with or without eclipse?
thank you

papa

-- 

2. Animating an Updating TextView

Animated TextView Not Updating..

Ok. Here is my problem.. I am a little new to android dev.. I'm having
a hard time understanding 2D graphics..

I was able to make my Layout rotated like iPhone's LandscapeLeft to
LandscapeRight.. It has a TextView that updated with accelerometer
values...
The problem is that after the animation the TextView stops updating..

I have read that this type of animation only moves the view.. and that
everything else is still in it's previous position... Can someone help
me understand. I have attached my project in case somebody wanted to
look at it..

ANY suggestions would be much appreciated.. Thanks..

The project is also in Github 
https://github.com/miscventura/AnimatingUpdatingTextView

Here is the code..

package org.example.hello;

import android.app.Activity;
.......
import android.widget.TextView;


public class Hello extends Activity implements SensorEventListener {
/** Called when the activity is first created. */

Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean previewing = false;
LayoutInflater controlInflater = null;

TextView numbersView;
TextView numbersView2;

// for orientation change
OrientationEventListener mOrientationEventListener;
int mDeviceOrientation;
public SensorManager sensorManager = null;
float accelerationX;
float accelerationY;

// ///Orientation//////
static final int lanscapeLeft = 2;
static final int lanscapeRight = 1;
int orientation = 2;

View viewControl;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// *******************************************
// full screen mode
// *******************************************
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FL AG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// *******************************************
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

//sets a floating layer
viewControl = getLayoutInflater().inflate(R.layout.mainview, null);
setContentView(viewControl);

numbersView = (TextView) findViewById(R.id.numbersview);
numbersView2 = (TextView) findViewById(R.id.numbersview2);



mOrientationEventListener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
mDeviceOrientation = orientation;
}
};

if (mOrientationEventListener.canDetectOrientation()) {
mOrientationEventListener.enable();
}
}

// 
///////////////////////////////////////////////////////////////////////////////////
// /////////////////////////ACCELEROMETER SET
// UP/////////////////////////////////////
// 
/////////////////////////////////////////////////////////////////////////////////
@Override
protected void onResume() {
super.onResume();
// Register this class as a listener for the accelerometer sensor
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELER OMETER),
SensorManager.SENSOR_DELAY_GAME);

}

public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub

}

public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
synchronized (this) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {

// high-pass filter to eliminate gravity
accelerationX = event.values[0];
accelerationY = event.values[1];
String accValue = String.format("%.1f", accelerationX);
String accValue2 = String.format("%.1f", accelerationY);

if (mDeviceOrientation <= 300 && mDeviceOrientation >= 240) {
animateRootViewToLanscapeLeft(viewControl);
}
if (mDeviceOrientation >= 60 && mDeviceOrientation <= 120) {
animateRootViewToLanscapeRight(viewControl);
}


numbersView.setText(accValue);

numbersView2.setText(accValue2);
}
}
}

public void animateRootViewToLanscapeLeft(View view) {
if (orientation == lanscapeRight) {
Animation spin = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.tolandscapeleft);
view.setAnimation(spin);
spin.setFillAfter(true);
spin.start();
orientation = lanscapeLeft;
}
}

public void animateRootViewToLanscapeRight(View view) {
if (orientation == lanscapeLeft) {
Animation spin = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.tolandscaperight);
view.setAnimation(spin);
spin.setFillAfter(true);
spin.start();
orientation = lanscapeRight;
}
}


}

-- 

3. StackView example as a non-widget application

4. Internet not working via adhoc network connection in galaxy ace GT-S5830

5. Removing a specific over lay item

6. How to connect to Internet with Wifi when no Cellular Service is present

7. C2DM server