こんにちは皆さん、スタック オーバーフローが初めてで、問題が発生しました。サーバーから文字列のリストを取得し、それを文字列の配列リストに渡します。それを別のクラスに渡してスピナアダプターとして機能させるまで、すべてが正常に見えます。その後、配列内の位置のコードバージョンを取得します。ストリング。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_category_select);
ArrayList < String > categories = new ArrayList < String > ();
PopulateSpinner(categories);
Log.d(TAG, "before spin adapter");
adapter = new SpinAdapter(this, android.R.layout.simple_spinner_item, categories);
}
private void PopulateSpinner(ArrayList < String > categories) {
BufferedReader in = null;
Log.d(TAG, "bufferReader");
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
Log.d(TAG, "request");
String Url = "http://www.youcode.ca/Lab02Servlet";
Log.d(TAG, Url);
Log.d(TAG, "Url");
request.setURI(new URI(Url.toString() + "?Service=categories"));
Log.d(TAG, "URI");
HttpResponse response = client.execute(request);
Log.d(TAG, "response"); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
Log.d(TAG, "in");
String line = "";
while ((line = in .readLine()) != null) {
Log.d(TAG, line);
CategoryItem temp = new CategoryItem();
temp.SETcategorystring(line);
categories.add(temp.toString());
}
/*for (String string : categories) test the aray to see if it has the content
{
Log.d(TAG, string.toString());
}*/
Log.d(TAG, "after the while");
}
private Context context;
private ArrayList < String > jitters;
private static final String TAG = "SpinAdapterActivity";
public SpinAdapter(Context context, int textViewResourceId, ArrayList < String > categories) {
super(context, textViewResourceId, categories);
this.context = context;
this.jitters = categories;
}@
Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
CategorySelect activity = (CategorySelect) context;
LayoutInflater inflater = activity.getLayoutInflater();
View spinnerRow = inflater.inflate(R.layout.category_textview, null);
TextView line = (TextView) spinnerRow.findViewById(R.id.Category_textview_id);
line.setText((String)(jitters.get(position)));
return spinnerRow;
}