我试图把这个JSON
{
"display_name": "Type of Business",
"field_type": "Drop Down Menu",
"option_value": "Education\r\nHealth\r\nComputers\r\nFood\r\nRetail\r\nOther"
},
进入一个ArrayList
然后Spinner
用那个填充我的ArrayList
。这是代码。
protected void onPostExecute(String string) {
// dismiss the dialog
pDialog.dismiss();
// loop through infoList
for (int i = 0; i < infoList.size(); i++) {
// get HashMap
HashMap<String, String> map = infoList.get(i);
// Create Spinner
if (map.get(TAG_FIELD).equals("Drop Down Menu")) {
Log.v("RESPONSE", "About to create a Drop Down Menu");
// find
LinearLayout content = (LinearLayout) view
.findViewById(R.id.genA_layout);
// create
TextView tv = new TextView(getActivity());
LinearLayout ll3 = new LinearLayout(getActivity());
ArrayList<String> spinnerArray = new ArrayList<String>();
ArrayAdapter<String> aa = new ArrayAdapter<String>(
getActivity(),
android.R.layout.simple_spinner_dropdown_item,
spinnerArray);
Spinner spinner = new Spinner(getActivity());
// set
tv.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT));
spinner.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.MATCH_PARENT));
ll3.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
tv.setText(map.get(TAG_NAME));
spinnerArray.add(map.get(TAG_VALUE));
spinner.setAdapter(aa);
ll3.setOrientation(LinearLayout.HORIZONTAL);
ll3.setGravity(Gravity.CENTER);
// add
ll3.addView(tv);
ll3.addView(spinner);
content.addView(ll3);
}
}
// find
LinearLayout loader = (LinearLayout) view
.findViewById(R.id.loader_layout);
Button save = (Button) view
.findViewById(R.id.generalAssets_save_button_ID);
// set
loader.setVisibility(View.GONE);
save.setVisibility(View.VISIBLE);
};
我失败了,因为我没有打破String
“\r\n”分隔符。现在我正在插入
Education\r\nHealth\r\nComputers\r\nFood\r\nRetail\r\nOther
的一个索引ArrayList
。
那么我该如何拆分呢?子串?分割功能?