How to get the data from an EditText? - android

I want to get the user input for the EditText and put it in a URL through String Concatenation but when the Button is clicked to get the data from URL, the app crashes. Also when i put value in concatenation manually, the data is fetched from the URL all fine

Related

Passing Edittext value to Get Request URL in Volley

I want to add edittext value to simple GET Request URL in Android. But I am facing some error while concatenation. This is what I am sending.
String forgot_email = et_email.getText().toString(); //gives me proper email output
final String final_url = "http:abc....../"+forgot_email.getText().toString(); // Here edittext value is not appending.
final_url = "http:abc....../" // logs value shows its not appending in the end.
I want send this URL to Server.
http:abc....../EMailID
Any responses will be highly appreciated.
I resolved it. Basically I write these two lines inside click listener.I had written outside previously . Thanks all
It should be either
String final_url = "http:abc....../"+et_email.getText().toString();
or
String final_url = "http:abc....../"+ forgot_email;

background color span not saved in sqlite android for API less than 25

I wanted to highlight part of my edit text like so:-
mySpannablestring.setSpan((new
BackgroundColorSpan(color)),0,mySpannablestring.length(),0);
//then set to editext
editext.setText(mySpannablestring);
I saved it as a String to database using HTML :-
String todatabase = Html.toHtml(editext.getText());
//then saved the String in sqlite.
Basically the code saves for basic rich-text operations like bold,italic and underline but in that highlight operation it saved only on API 25 not even in API 23 .The intended text gets highlighted successfully but isn't saved .
Sure it will not be saved. You'r trying to save String whitch is not Spannable. If you really want to save SpannableString you need some way to serialize and then deserialize value that you receive from textView.getText(). And note, that getText() returns CharSequence and not String. And this CharSequense basically can be anything.

Pass EditText data automatically to another activity EditText, only if it gets data in some pattern

I am trying to pass data from web application to EditText using json.
Already i had completed the json part in my android app.Now i can able to send data from web application to MY app's EditText as
{
"sender": "web app client",
"command": {
"type": "System.Clipboard",
"text": "hello"
}
}
Now i need to send this "hello" to the same app's another activity EditText automatically whenever it gets data like "text":"data" .
Answers would be appreciated.
To send String from first activity
intent.putExtra("MyClass", value);
To retrieve String in second Activity
getIntent().getStringExtra("MyClass");
When you send your text value either it is numerical or string
Intent intent=new Intent() intent.putExtra("key",edittext.getText.toString())
and then get This next to
secondActivity
getIntent.getStringExtra("key");
you will get a String here set this string to Your EditText simple.

How to pass a 'json' parameter with an url in android?

I have check-boxes on one page and when user selects a particular check-box, it passes the id associated with it to the next page, on this page I want to send those ids in the form of url to a wcf service.
My url is
http://rankup.co.uk/service1.svc/getTopic/
After adding the parameters, I want this json to pass with the url like
http://rankup.co.uk/service1.svc/getTopic/20,32
where "20,32" are the ids selected by the user (it may vary accordingly)
Can anybody tell me how to do this?
Just pass the parameters with the Intent from the calling activity like this
intent.putExtra("parameters", "20,32");
Then retrieve this parameter from the second activity :
String parameters = getIntent().getStringExtra("parameters", 0.0);
After that make the url like this :
String url = "http://rankup.co.uk/service1.svc/getTopic/ "+parameters;
Second part : to get and parse the json you can see this tutorial.
Happy Coding.
You can create an array list or can create an string variable. On clicking on checkbox, you can add all ids in a comma separated list or array and then can send using intent to the next screen.

Difficulty in passing text as parameter from android to jsp page

I am trying to pass a text from the spinner. Actually the spinner contains the textx which I have fetched from the server side of my application.
So what I am trying to do is that, as soon as I select text from the spinner, I want that string to be passed to the server side. So here i am passing the text to a function which can make a request to the JSP.
Main part of the code(android)
categ = ((TextView) selectedItemView).getText().toString();
postData(categ);
//Remaining section
public void postData(categ)
{
String page="processing_pages/individual_phone_communicator.jsp?rom="+categ;
result = ws.getWebData(page);
if (result != null)
plotData();
else
alerter("null");
}
(It is returning a null value always.But when i am directly running the same query without any parameter and taking the value directly at the JSP page, it shows result)
Now it will move to the JSP.
String hk=request.getParameter("rom");
Now i am running a query like this:
sqlstatem="select first_name,latitude,longitude from tbluserdetails where user_id=(select user_id from tblindividual_job where jcat_id=(select jcat_id from tbljobcat where job_name='"+hk+"'))";
I am expecting it to give back data in the form of json array. But instead it is showing an error. I tried entering the parameter directly from browser even. Sometimes, the page is displaying correct answer with above query. This makes me more confusing. But when i tried with numbers such as 1 or 2 from the eclipse:
String page="processing_pages/individual_phone_communicator.jsp?rom=2"
and modified the query by trying the exact word instead of 'hk' like this
int rom=Integer.parseInt(request.getParameter("romo"));
if(rom==1)
{
sqlstatem="select first_name,latitude,longitude from tbluserdetails";
}
else
{
sqlstatem="select first_name,latitude,longitude from tbluserdetails where user_id=(select user_id from tblindividual_job where jcat_id=(select jcat_id from tbljobcat where job_name='Blood donar'))";
}
it is running correctly. From browser also, it is running correctly when i pass integer as parameter. But i need it to be running by taking a text from the emulator as parameter.
But when I try, like this:
String page="processing_pages/individual_phone_communicator.jsp?rom=Blood donor"
Then also i am getting null as result. What I assume is that, my JSP page is only taking integer parameters, I don't know why it is happening.
I am using net beans for JSP. Kindly find me a solution for this issue. Kindly ignore if the question is childish, as i am just a beginner.
I don't know what the "ws" variable is, but the IP for your local machine (not the phone) in the android emulator is 10.0.2.2. So any URL pointing to a local web app on your machine should start with http://10.0.2.2/...
Mike

Categories

Resources