0

私はこれを入れようとしています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それを mySpinnerに入力し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

の 1 つのインデックスにArrayList

では、これをどのように分割しますか?部分文字列? 分割機能?

4

2 に答える 2

1
    int index=0;
    int index2=0;
    ArrayList<String> strArrayList= new ArrayList<String>();
    while(index!=-1)
    {
        index = str.indexOf("\r\n");
        index2 = index+4;
        if(index!=-1 && index2!=-1)
        {
            strArrayList.add(str.substring(0, index));
            str = str.substring(index2+1, str.length();

        }
    }   
于 2013-06-05T16:42:41.893 に答える