我已经开发了一个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 );


这是我的网址:
[http://api1.sfsfsfsff.com/dev/categories/?fields=&categoryid=10&access_token=bfb787a6e1112][1]

我直接提到categoryid = 10表示已淘汰所有产品。

但我必须更改此网址,例如:
[http://api1.sfsfsfsfsf.com/dev/categories/?fields=&categoryid="+mTitle+"&access_token=bfb787a6e1112][2]

Nw我已经更改了我的URL,例如categoryid =“ + mTitle +”表示未显示所有产品。

mTitle的价值来自我以前的活动。

我的代码有什么问题。

编辑:

我的mTitle值为10。我必须编写类似均码的代码

grandtotal.setText(“ Welcome,” + mTitle);

其成功显示的mTitle值。

grandtotal.setText(“ Welcome,” + URL);

意味着给了我零值

最佳答案

您的密码

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。

09-10 23:01