Reputation: 143
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
Upvotes: 0
Views: 724
Reputation: 535
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.
Upvotes: 1
Reputation: 1
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);
Upvotes: 0