0

私は1つのAndroidアプリケーションを開発しました。

ここでは、文字列値をurlに渡す必要があります。文字列値をurlに渡す方法を教えてください。これらの解決策を教えてください。

 String mTitle;

           String URL = "http://api1.sfsfsfffsf.com/dev/categories/?fields=&categoryid="+mTitle+"&access_token=bfb787a6e1";
          static String KEY_CATEGORY = "category";
// public static final String URL_Address=null;
        static final String KEY_TITLE = "categoryName";
        static final String KEY_NAME ="categoryId";
          static final String KEY_SUBCATE = "categoryId";
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.subcate);
    Bundle b = getIntent().getExtras();
 mTitle = b.getString(KEY_SUBCATE);
 TextView grandtotal = (TextView) findViewById(R.id.subcate);
   grandtotal.setText("Welcome ," + mTitle );

これは私のURLです:[http://api1.sfsfsfsff.com/dev/categories/?fields3%categoryid=10&access_token=bfb787a6e1112] [1]

私が直接言及したcategoryid=10は、すべての製品を無効にしたことを意味します。

ただし、次のようにこのURLを変更する必要があります。

カテゴリID="+ mTitle +"のようにURLを変更したので、すべての製品が表示されないことを意味します。

mTitleの価値は、私の以前の活動から得られています。

私のコードの何が問題なのですか。

編集

私のmTitle値は10です。私は手段のようなコードを書かなければなりません

grandtotal.setText( "ようこそ、" + mTitle);

表示されたmTitle値は正常に表示されます。

grandtotal.setText( "ようこそ、" + URL);

私にnull値を与えたことを意味します

4

2 に答える 2

1

あなたのコード

String mTitle;

           String URL = "http://api1.sfsfsffsf.com/dev/categories/?fields=&categoryid=" + mTitle + "&access_token=bfb787a";
          static String KEY_CATEGORY = "category";
// public static final String URL_Address=null;
        static final String KEY_TITLE = "categoryName";
        static final String KEY_NAME ="categoryId";
          static final String KEY_SUBCATE = "categoryId";
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.subcate);
    Bundle b = getIntent().getExtras();
 mTitle = b.getString(KEY_SUBCATE);
 TextView grandtotal = (TextView) findViewById(R.id.subcate);
   grandtotal.setText("Welcome ," + mTitle );

エラー:

 String URL = "http://api1.sfsfsffsf.com/dev/categories/?fields=&categoryid=" + mTitle + "&access_token=bfb787a";

正しいコード:

String mTitle;

               String URL;
              static String KEY_CATEGORY = "category";
    // public static final String URL_Address=null;
            static final String KEY_TITLE = "categoryName";
            static final String KEY_NAME ="categoryId";
              static final String KEY_SUBCATE = "categoryId";
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.subcate);
        Bundle b = getIntent().getExtras();
     mTitle = b.getString(KEY_SUBCATE);

     URL = "http://api1.sfsfsffsf.com/dev/categories/?fields=&categoryid=" + mTitle +       "&access_token=bfb787a";
 TextView grandtotal = (TextView) findViewById(R.id.subcate);
   grandtotal.setText("Welcome ," + mTitle );

mTitleは後で初期化されるため、その後のみURLを初期化する必要があります。

于 2012-12-28T07:31:07.157 に答える
0

URLを文字列として渡します:-

String mTitle;
mTitle = b.getString(KEY_SUBCATE);
TextView grandtotal = (TextView) findViewById(R.id.subcate);  
String url="http://api1.sfsfsffsf.com/dev/categories/?   fields=&categoryid="+mTitle+"&access_token=";
grandtotal.setText(url);
于 2012-12-28T05:20:13.950 に答える