0

i have develop one android application.

here i have to pass string value to url.please tell me how can i pass the string value to url.give me solution for these.

 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 );

This is my url: [http://api1.sfsfsfsff.com/dev/categories/?fields=&categoryid=10&access_token=bfb787a6e1112][1]

I have mentioned directly categoryid=10 means have disaplyed all product.

But I have to change this url like: [http://api1.sfsfsfsfsf.com/dev/categories/?fields=&categoryid="+mTitle+"&access_token=bfb787a6e1112][2]

Nw i have changed my url like categoryid="+mTitle+" means not displayed all products.

mTitle value is getting from my pervious activity.

whats wrong in my code.

EDIT:

my mTitle value is 10.i have to wrote the code like means

grandtotal.setText("Welcome ," + mTitle );

its displayed mTitle value successfully.

grandtotal.setText("Welcome ," + URL );

means gave me null value

2
  • just check what is your mTitle value Commented Dec 28, 2012 at 5:30
  • my mTitle value is 10.i have to wrote the code like means grandtotal.setText("Welcome ," + mTitle ); its displayed mTitle value successfully.grandtotal.setText("Welcome ," + URL ); means gave me null value Commented Dec 28, 2012 at 5:44

2 Answers 2

1

Your code

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 );

Error:

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

Correct Code:

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 );

Your mTitle is getting Initialized afterwards so you need to initialize URL after that only.

Sign up to request clarification or add additional context in comments.

Comments

0

Pass your Url as a string :-

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);

1 Comment

my mTitle value is 10.i have to wrote the code like means grandtotal.setText("Welcome ," + mTitle ); its displayed mTitle value is 10 successfully.grandtotal.setText("Welcome ," + URL ); means gave me null value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.