Cofeina Cofeina - 1 year ago 86
Java Question

How to get the info into an Object

I have an

in java (Android). If I print this object in Logcat, I can see 2
s. Now, I need extract the
s. How?

listaFound.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {

Object a = myAdapter.getAdapter().getItem(myItemInt);

Log.d("tututu", "onItemClick: "+a.toString());


The Response of log is:

onItemClick: Neo3600


I need to get the Neo3600 and MAC adress strings.

Answer Source

This is the adapter: mArrayAdapter.add(device.getName() + "\n" + device.getAddress());

According to your comment above, the following should work:

// the (String) cast may be unnecessary depending on your implementation
String device = (String) myAdapter.getAdapter().getItem(myItemInt);
String[] nameAndAddress = device.split("\n");

String name = nameAndAddress[0];
String macAddress = nameAndAddress[1];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download