0

我已经开发了一个 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("欢迎 ," + mTitle );

其显示的 mTitle 值成功。

grandtotal.setText("欢迎 ," + URL );

意味着给了我空值

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

将您的网址作为字符串传递:-

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 回答