0

I have static ArrayList<Batch>. i want to remove which object contain productcode

This is my Batch Entity

public class BatchControl implements Parcelable{
  private String productCode;
  private String lotNumber;
  private String batchSerialNumber;
  private double quantity   ;
  private int sequence;
  private String productName;
  private String type;
  //Setter & getter
 }

This is my removing object

  static ArrayList<String> lstString = new ArrayList<String>();
  for (Iterator<Batch> i = lstString.iterator(); i.hasNext(); ) {
        Batch value=(Batch )i.next();
        if(value.getSequence() == iVal) {
            lstString.remove(value);
        }
    }

iVal is Android TableLayout contain the row number.

        String number = txtNumber.getText().toString();
    iVal = Integer.parseInt(number);

But it didn't remove which object have iValue. Because of the resoan static arraylist so, each & every time when i remove size going to change.

Please help me out.

Thanks in advance.


The FB.getLoginStatus() no response

I am doing a demo of facebookapp that only wants to get a acces_token from the app. The app is totally client side and i don't have the possibility of server-side. At this moment I load correctly the javascript sdk asynchronously and init the facebook with this params:

FB.init(
    {
        appId: 'XXXX',   //XXXX is my AppID
        // channelUrl: http://bla,
        status: true,
        cookie: true,
        xfbml: true,
        oauth: true
    });

My problem is that the function:

 FB.getLoginStatus(function (response) 
    {
        alert('Check login: ' + response);
        console.log("3");
        if (response.status === 'connected') 
        {
            // the user is logged in and has authenticated your
            // app, and response.authResponse supplies
            // the user's ID, a valid access token, a signed
            // request, and the time the access token 
            // and signed request each expire
            var uid = response.authResponse.userID;
            var accessToken = response.authResponse.accessToken;
            console.log("Access Token: " + accessToken);
        } 
        else if (response.status === 'not_authorized') 
        {
            // the user is logged in to Facebook, 
            // but has not authenticated your app
        } 
        else 
        {
            // the user isn't logged in to Facebook.
        }

    });

no response anything.

Anyone knows why??

4

3 回答 3

4

You should use i.remove(), please refer to http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Iterator.html

于 2012-05-18T09:57:54.280 回答
1

When using an Iterator on a list, you can safely remove the current element (regarding position or index in the list) with Iterator.remove().

for (Iterator<Batch> i = lstString.iterator(); i.hasNext(); ) {
    Batch value=(Batch )i.next();
    if(lstBatCtrl.get(k).getSequence() == iVal) {
        i.remove();
    }
}

Take into account that using remove() on a static List can yield to problems if there are concurrent modifications on the List. Citing Iterator.remove()'s javadoc:

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method

于 2012-05-18T09:59:50.763 回答
1

使用以下代码:

  for (Iterator<Batch> i = lstString.iterator(); i.hasNext(); ) {
        Batch value=(Batch )i.next();
        if(value.getSequence() == iVal) {
            i.remove();
        }
    }
于 2012-05-18T10:00:30.427 回答