Cofeina Cofeina - 5 months ago 15
Java Question

How to get the info into an Object

I have an

Object
in java (Android). If I print this object in Logcat, I can see 2
String
s. Now, I need extract the
String
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


9C:04:73:81:F5:94

I need to get the Neo3600 and MAC adress strings.

Answer

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];
Comments