Sony Xperia Z3 Lollipop Framework Ported to CM12

Android 5.0 for Xperia has a unique look and feel. You don’t have to get a Sony … more

Do You Use Recents as a Task Switcher?

Google introduced a revamped Recents interface with Lollipop in the hopes of making it easier for … more

YU Yureka All-in-One ToolBox (CM12S Only)

This packed toolbox by XDA Senior Member gohel.vishal makes many useful tweaks … more

Sony Xperia Z4 Forum Now Available

Sony’s Xperia line has seen plenty of development on XDA, and now that the Xperia Z4 has been … more
Post Reply Subscribe to Thread Email Thread

ArrayList<Integer> 's remove method confusing?

22nd June 2014, 03:53 PM |#1  
arpitkh96's Avatar
OP Senior Member
Flag panipat
Thanks Meter: 571
 
1,145 posts
Join Date:Joined: Feb 2012
Donate to Me
More
Suppose I added a digit '1' to the arraylist<Integer> which is at position 0.So when I call remove method like this.
array.remove(1);
It gives an exception.although the method remove(object) exists.so I how can I remove the object(integer) by not using the position

Sent from my GT-S5570 using XDA Premium 4 mobile app
 
 
22nd June 2014, 05:16 PM |#2  
SimplicityApks's Avatar
Senior Member
Flag Aachen
Thanks Meter: 340
 
346 posts
Join Date:Joined: May 2013
More
Quote:
Originally Posted by arpitkh96

Suppose I added a digit '1' to the arraylist<Integer> which is at position 0.So when I call remove method like this.
array.remove(1);
It gives an exception.although the method remove(object) exists.so I how can I remove the object(integer) by not using the position

Sent from my GT-S5570 using XDA Premium 4 mobile app

array.remove(new Integer(1));
22nd June 2014, 07:08 PM |#3  
arpitkh96's Avatar
OP Senior Member
Flag panipat
Thanks Meter: 571
 
1,145 posts
Join Date:Joined: Feb 2012
Donate to Me
More
Quote:
Originally Posted by SimplicityApks

array.remove(new Integer(1));

That didn't worked.I am using it like this
Code:
 
//CopyIds is the arraylist
private BroadcastReceiver Copy_Receiver = new BroadcastReceiver(){

@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Bundle b=arg1.getExtras();
if(b!=null){
int id=b.getInt("id");
Integer id1=new Integer(id);
if(CopyIds.contains(id)){

boolean completed=b.getBoolean("COPY_COMPLETED",false);
View process=rootView.findViewWithTag("copy"+id);
  if(completed){ rootView.removeViewInLayout(process);CopyIds.remove(id1);}
else{
String name=b.getString("name");
int p1=b.getInt("p1");
int p2=b.getInt("p2");
long total=b.getLong("total");
long done=b.getLong("done");
  ((TextView)process.findViewById(R.id.progressText)).setText("Copying \n"+name+"\n"+utils.readableFileSize(done)+"/"+utils.readableFileSize(total)+"\n"+p1+"%");
ProgressBar p=(ProgressBar)process.findViewById(R.id.progressBar1);
p.setProgress(p1);
p.setSecondaryProgress(p2);}
}else{
View root=getActivity().getLayoutInflater().inflate(R.layout.processrow, null);
root.setPaddingRelative(10,10,10,10);
String name=b.getString("name");
int p1=b.getInt("p1");
int p2=b.getInt("p2");
root.setTag("copy"+id);
((TextView)root.findViewById(R.id.progressText)).setText("Copying \n"+name);
ProgressBar p=(ProgressBar)root.findViewById(R.id.progressBar1);
p.setProgress(p1);
p.setSecondaryProgress(p2);
CopyIds.add(id);
rootView.addView(root);
}
}
}};
Log says error receiving broadcast.arryindexoutofbounds exception ,size 1 index 1

Sent from my GT-S5570 using XDA Premium 4 mobile app
22nd June 2014, 09:19 PM |#4  
SimplicityApks's Avatar
Senior Member
Flag Aachen
Thanks Meter: 340
 
346 posts
Join Date:Joined: May 2013
More
Quote:
Originally Posted by arpitkh96

That didn't worked.I am using it like this

Code:
 
//CopyIds is the arraylist
private BroadcastReceiver Copy_Receiver = new BroadcastReceiver(){

@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Bundle b=arg1.getExtras();
if(b!=null){
int id=b.getInt("id");
Integer id1=new Integer(id);
if(CopyIds.contains(id)){

boolean completed=b.getBoolean("COPY_COMPLETED",false);
View process=rootView.findViewWithTag("copy"+id);
  if(completed){ rootView.removeViewInLayout(process);CopyIds.remove(id1);}
else{
String name=b.getString("name");
int p1=b.getInt("p1");
int p2=b.getInt("p2");
long total=b.getLong("total");
long done=b.getLong("done");
  ((TextView)process.findViewById(R.id.progressText)).setText("Copying \n"+name+"\n"+utils.readableFileSize(done)+"/"+utils.readableFileSize(total)+"\n"+p1+"%");
ProgressBar p=(ProgressBar)process.findViewById(R.id.progressBar1);
p.setProgress(p1);
p.setSecondaryProgress(p2);}
}else{
View root=getActivity().getLayoutInflater().inflate(R.layout.processrow, null);
root.setPaddingRelative(10,10,10,10);
String name=b.getString("name");
int p1=b.getInt("p1");
int p2=b.getInt("p2");
root.setTag("copy"+id);
((TextView)root.findViewById(R.id.progressText)).setText("Copying \n"+name);
ProgressBar p=(ProgressBar)root.findViewById(R.id.progressBar1);
p.setProgress(p1);
p.setSecondaryProgress(p2);
CopyIds.add(id);
rootView.addView(root);
}
}
}};
Log says error receiving broadcast.arryindexoutofbounds exception ,size 1 index 1

Strange since I don't get any compile time errors (sorry don't have time to test it right now) and that should be the way to do it...

Anyway, if it still doesn't work for you, just manually search for the right index using get().equals in a for loop and remove the element at the right index then... (that's what the remove(Object) method does anyway).
23rd June 2014, 02:56 AM |#5  
Member
Thanks Meter: 5
 
54 posts
Join Date:Joined: Feb 2012
Quote:
Originally Posted by SimplicityApks

array.remove(new Integer(1));

That works. But why ArrayList is not generified. I would like to use it like:
Code:
arrayList.<Integer>remove(new Integer(1));
It would throw Compiler time Error in case if you pass object of wrong type, which would safe time people like OP.
23rd June 2014, 08:16 AM |#6  
arpitkh96's Avatar
OP Senior Member
Flag panipat
Thanks Meter: 571
 
1,145 posts
Join Date:Joined: Feb 2012
Donate to Me
More
Quote:
Originally Posted by SimplicityApks

Strange since I don't get any compile time errors (sorry don't have time to test it right now) and that should be the way to do it...

Anyway, if it still doesn't work for you, just manually search for the right index using get().equals in a for loop and remove the element at the right index then... (that's what the remove(Object) method does anyway).

I solved it

Sent from my GT-S5570 using XDA Premium 4 mobile app
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes