Click here to Skip to main content
15,905,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Java
// Create ImageView Dynamically 
int img1_id,img2_id; 
ImageView img_view = new ImageView(this); 
img_view.setBackgroundResource(R.drawable.bulb); 
img_view.setId(j); 
ll.addView(img_view); 
img_view.setOnClickListener(new View.OnClickListener() { 
@Override 
public void onClick(View v) { 
switch (v.getId()) { 
case 0: 
img1_id=v.getId(); 
break; 
case 1: 
img2_id=v.getId(); 
break;}}}); 

I have a tcp/ip connection in this application. So when i receive data from server, based on the byte received image view needs to change the image. ie, I need to change only for imageview that has id 1. How is it possble.
Java
Runnable run=new Runnable() 
{ 
@Override 
public void run() { 
receive_Data();//function called here 
} 
}; 
public void receive_Data() 
{ 
try 
{ 
if(GlobalClass.socket.isConnected()) 
{ 
GlobalClass.buffer_len=GlobalClass.socket.getInputStream().available(); 
if(GlobalClass.buffer_len>0) 
{ 
GlobalClass.socket.getInputStream().read(GlobalClass.buffer,0,GlobalClass.buffer_len); 
switch(GlobalClass.buffer[25]) 
{ 
case 0x08: 
switch(GlobalClass.buffer[30]) 
{ 
case 0x00: 
/// here is where I need to change the image. 
break; 
case 0x01: 
/// here is where I need to change the image. 
break 
} 
} 
} 
} 
} 
} 


handler.post(run); will be called in oncreate(); so that it will be running in background. Pls help
Posted
Updated 28-Dec-14 19:24pm
v2

1 solution

I think you need something like this:
imageview drawable id in android[^]
 
Share this answer
 
Comments
User1454 29-Dec-14 2:21am    
sir... i have gone through that link.....but i think its for changing the image in imageview click right. But I need it to change only when I get response from server. Is it possible ??
ridoy 29-Dec-14 2:30am    
Yes it's possible.Set a flag to check your server response status. when it returns true that means a valid image would be found on server for that imageview id then change it accordingly.
User1454 29-Dec-14 3:36am    
k let me try thanq!!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900