1
我已遵循其餘部分的說明here。但是,這似乎是我的編碼問題。最初,當我第一次到達這個活動時,我的小工具應該在列表中顯示第一個項目,但不是隻是空的。幸運的是,當我點擊微調器來做出我的選擇時,該列表仍然存在。而且,在我做出選擇後,敬酒並沒有出現。我不知道這是否是它,因爲它彈出在DDMS後,我有讓我選擇的原因:從微調框中獲取所選項目
09-07 06:30:06.470: WARN/InputManagerService(50): Window already focused, ignoring focus gain of: [email protected]
下面是本次活動的編碼:
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>
發佈您的代碼。 –
您發佈的代碼部分似乎沒問題。所以錯誤應該是其他地方... –
嗨@Nishant,我已經更新了我的問題與編碼。 – user918197