UDP Sending Android / Java

31 2015

Server side:

String msg = “Hello UDP!”;
int server_port = 12345;
DatagramSocket UDP = new DatagramSocket();
InetAddress local = InetAddress.getByName(“192.168.1.1”);
int msg_len = msg.length();
byte[] message = msg.getBytes();
DatagramPacket packet = new DatagramPacket(message, msg_len,local,server_port);
UDP.send(packet);

Client side:

int server_port = 12345;
byte[] incoming_message = new byte[1500];
DatagramPacket DG_Packet = new DatagramPacket(incoming_message, incoming_message.length);
DatagramSocket DG_Socket = new DatagramSocket(server_port);
DG_Socket.receive(DG_Packet);
String text = new String(incoming_message, , 0, DG_Packet.getLength());
DG_Socket.close();

Android – List View Alternate Row Color

27 2014

Try this code snippet.
class SpecialAdapter extends ArrayAdapter
{

public SpecialAdapter(Context context, int resource,List Objects) {
super(context, resource,Objects);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if(position % 2 == 0)
{
view.setBackgroundColor(Color.rgb(245, 245, 245));
}
return view;
}
}

Call :


ArrayAdapter arrayadapter = null;
arrayadapter = new SpecialAdapter(this, R.layout.row, item);
setListAdapter(arrayadapter);