I have follow what the rest had stated here. However, that seems to be a problem with my coding. Initially, my spinner should have shown the first item in the list when i first arrive at this activity but not it is just empty. Luckily the list is still there when i click on the spinner to make my selection. And also, after i have made my selection, the toast did not show up. I am not sure whether this is the cause of it as it pop out in the DDMS after i have make my selection:
09-07 06:30:06.470: WARN/InputManagerService(50): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43cbe3b0
Here is the coding for this activity:
package android.wps;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
public class locationFinder extends Activity {
WifiPositioningServices wifiPositioningServices = new WifiPositioningServices();
ArrayList<Profile> profileList = new ArrayList<Profile>();
ArrayList<String> profileNames = new ArrayList<String>();
ArrayList<String> mapNames = new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationfinder);
String[] temp = wifiPositioningServices.GetAllProfileData();
final Spinner profiles = (Spinner)findViewById(R.id.profileList);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,
profileNames);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
profiles.setAdapter(spinnerArrayAdapter);
profiles.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long arg3) {
// TODO Auto-generated method stub
String test = parent.getItemAtPosition(pos).toString();
Toast toast = Toast.makeText(parent.getContext(), test, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
//store all profile data into a ArrayList of Profile objects
for(int i=0; i<temp.length; i++){
String[] result = temp[i].split(",");
Profile profile = new Profile();
profile.setProfileName(result[0]);
profile.setOwner(result[1]);
profile.setMap(result[2]);
profile.setVisible(result[3]);
boolean visible = Boolean.valueOf(result[3]);
if(visible){
//if visible is true, then add profile name and mac filters into arraylist
profileNames.add(result[0]);
for(int j=4; j<result.length; j++){
profile.setMacFiltersList(result[j]);
}
}
profileList.add(profile);
}
}
}
locationfiner.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/txtPofile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile:"
android:textStyle="bold"
android:layout_x="10px"
android:layout_y="12px"
>
</TextView>
<Spinner
android:id="@+id/profileList"
android:layout_width="245px"
android:layout_height="36px"
android:layout_x="70px"
android:layout_y="12px"
>
</Spinner>
<TextView
android:id="@+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_x="0px"
android:layout_y="32px"
/>
</AbsoluteLayout>