Here is my code:http://pastebin.com/Xq7wkBLk
Whenever I press the load button the textview never changes.. its as if the buttons are not working.. I hope anyone can help me.
First, use a bunch of Log.d(string, sting) to check if your methods are called, makes life much easier.
Second, just a wild try.. Try in your postExeculte: InternalData.this.dataResult.setText(result);
prototype-U said:
Here is my code:http://pastebin.com/Xq7wkBLk
Whenever I press the load button the textview never changes.. its as if the buttons are not working.. I hope anyone can help me.
Click to expand...
Click to collapse
I am not positive but in your doInBackground you return null. So in the postExecute the result is null and you are setting the text to the result. That seems to me what your problem might be. try return a string that says failed to see if it is going to that return statement.
You haven't declared what the String 'result' is, so it looks like you have trying to setText to nothing.
It could also be what Acela said, instead of returning a string in doInBackground, you have it set to return null.
LOL guys the error is on line 113 and 117.. spelling mistake..
and now its workng like a charm..
forgot to get this thread closed
Thread Closed as per OP....
Related
I have a edit able text box that is next to a button lets say onclick of the button it will take the text from the editable text box and converted to an integer so it can be subracted by.. oh lets say 32 so my first method was this.
number = EText.getText();
textOutcome.setText(number - 32);
this gave me an error of
The operator - is undefined for the argument type(s) Editable, int
my second attempt was
textOutcome.setText((Integer.parseInt(EText.getText().toString()) - 32));
This gave me no errors and it ran fine untill i clicked the button which causes the command above to run. and it force closed my application.
Does any one have any ideas i can do, or any sample code?
Thanks,
Blue.
Bumping the topic.
Please can anyone help me with this..!
Have you tried stepping through the code with the debugger? Otherwise, the code you posted looks fine. There is probably something else at play here.
Basicall it force closes whea subtraction is made..
Sent from my Samsung Epic 4g.
Ahh the debugger found something early in the code thanks for the idea !
You have to do any mathematical arithmetic with the integer type, not with string, So when you extract the number from the EditText you have to convert the string into a integer, or whatever type of number it may be.
WHen you have the integer then you can apply the arithmetic.
when this is done you then have to convert the total into a string type again.
Hope this helps.
So basically im going to write a little of code off the top of my head which obviously can have errors. Since im not testing it.
EditText txbox = (EditText)findViewById(R.id.EditText01);
String txdata = txbox.getText().toString();
int txval = Integer.ParseInt(txdata);
//you should make sure that the value is an integer, if not i think //Integer.ParseInt() will just cut off the rest if its irrational.
//Now you can do arithmetic//
int b = 2;
int t;
t = txval - b;
//The total value is in variable t.
So lets convert this into a string and put it back into an object like edittext or textview
txbox.setText(String.valueOf(t));
//Thats all, hope that helps.
Hi everyone .
Can I combine to Texts into one TextView ?
I know its very ununderstandable . So let's shape it :
Imagine I have to Buttons That navigates to two different activities which both Have one view , one code but different texts .
Now imagine I have 1hunderd of them .
Can I make just one activity with one TextView item but the texts inside it differs depending on choosing different buttons ? If not understandable again let me know please .
Thanks in advanced
Yeah, you can:
When the button is clicked, do something like this:
Code:
TextView tv = (TextView) findViewById(R.id.[id of the text view]);
tv.setText([either the resource id or the text]);
You can check which text is displayed using the getText() method of the TextView and then display the other text using the method I gave you above. :good:
Guys. Help me. I'm learning to ''Respond to the Send Button'' but I don't know what to do. I follow this step but I still can't understand.
http://developer.android.com/training/basics/firstapp/starting-activity.html
If you guys can help me, I'm really grateful.
Merivex95 said:
Guys. Help me. I'm learning to ''Respond to the Send Button'' but I don't know what to do. I follow this step but I still can't understand.
http://developer.android.com/trainin...-activity.html
If you guys can help me, I'm really grateful.
Click to expand...
Click to collapse
That link didn't work, but if you Google 'android java button onclick listener' that will get you started with plenty of helpful links.
When the button is clicked, you then need to check the content of the Edit Text field - Something like this:
Code:
public void onClick(final View v) {
final String commandText = inputText.getText().toString();
if (commandText != null && commandText.length() > 0) {
Where inputText is the Edit Text field you've assigned in your OnCreate method.
Getting started involves a lot of head scratching, but don't give up! There's so much Open Source code out there, that the penny will drop soon.
brandall said:
That link didn't work, but if you Google 'android java button onclick listener' that will get you started with plenty of helpful links.
When the button is clicked, you then need to check the content of the Edit Text field - Something like this:
Code:
public void onClick(final View v) {
final String commandText = inputText.getText().toString();
if (commandText != null && commandText.length() > 0) {
Where inputText is the Edit Text field you've assigned in your OnCreate method.
Getting started involves a lot of head scratching, but don't give up! There's so much Open Source code out there, that the penny will drop soon.
Click to expand...
Click to collapse
OMG !! this is the link : http://developer.android.com/training/basics/firstapp/starting-activity.html
I don't know how to compile the code properly. hummmm ... maybe you can help me by correcting my code ?
Paste code (variables, functions, etc) inside your MainActivity class and don't write 3 dots, it's just a replacement for skipped parts
Mikanoshi said:
Paste code (variables, functions, etc) inside your MainActivity class and don't write 3 dots, it's just a replacement for skipped parts
Click to expand...
Click to collapse
Ohhh yeahhh :cyclops: .. how can I be so stupid
btw ,, where should I put this code ?
code:
Code:
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
Code:
Merivex95 said:
btw ,, where should I put this code ?
Click to expand...
Click to collapse
Replace existing onCreate function with it.
Mikanoshi said:
Replace existing onCreate function with it.
Click to expand...
Click to collapse
But I get an error after doing that ..
Merivex95 said:
But I get an error after doing that ..
Click to expand...
Click to collapse
You need to import TextView and Intent first. Just hover over the names and select import from the menu you will see.
Seriously, my advice would be to learn and understand Java first. It doesn't make sense to learn Android if you don't know Java (and it won't work).
nikwen said:
You need to import TextView and Intent first. Just hover over the names and select import from the menu you will see.
Seriously, my advice would be to learn and understand Java first. It doesn't make sense to learn Android if you don't know Java (and it won't work).
Click to expand...
Click to collapse
Thanks for the advice
nikwen said:
It doesn't make sense to learn Android if you don't know Java (and it won't work).
Click to expand...
Click to collapse
Unless you know any other similar languages. Java was the easiest lang to learn for me, after years of writing on Object Pascal/Object C/C++/JavaScript/PHP. The most troublesome part of coding for Android is creating an UI, especially cross-version compatible :laugh:
I'm trying to build a app that frst checks for valid emal ids and accodingly executes the code..
I have two layouts where
one is the actuall app..
two is a exit page..
i get an eror and i understand y... but how do i solve it??
So in a simple way this is the code
Code:
get user details
if(condition)
setContentView(xyz)
code_xyz
else
seContentView(abc)
code_abc..
code_abc..
what happns after the setConentView(abc) is the code fr the actual app...
whenn rogue user is detected, i set content view to xyz, it continues to execute rmaining code meant for abc... how do i stop this??
code_xyz contans code for one exit button.. thats it..
i want code to stop at that point... How do i this??
nvyaniv said:
I'm trying to build a app that frst checks for valid emal ids and accodingly executes the code..
I have two layouts where
one is the actuall app..
two is a exit page..
i get an eror and i understand y... but how do i solve it??
So in a simple way this is the code
Code:
get user details
if(condition)
setContentView(xyz)
code_xyz
else
seContentView(abc)
code_abc..
code_abc..
what happns after the setConentView(abc) is the code fr the actual app...
whenn rogue user is detected, i set content view to xyz, it continues to execute rmaining code meant for abc... how do i stop this??
code_xyz contans code for one exit button.. thats it..
i want code to stop at that point... How do i this??
Click to expand...
Click to collapse
It should work like this, don't forget the curly brackets around the statements between if() and else...
As said SimplicityApks, brackets are very important, you must use them if you have more than one line of code after "if" and "else", otherwise it will not work.
the correct structure in your case is :
if (condition) {
setContentView(view1);
do somthing X;
} else {
setContentView(view2);
do somthing Y;
}
You can do it this way too:
if (condition) {
setContentView(view1);
do somthing X;
return;
}
setContentView(view2);
do somthing Y;
ok my bad.. i guess my bad for missing out on few more details..
once we out of the main function... there are a couple more outsie of it which get executed... that is the problem.. this are mostly like your onclick listner and stuff...
since these buttons etc are part of main, it pops an error when the condition goes to the exit page...
Hope i waas able to explain it properly...
nvyaniv said:
ok my bad.. i guess my bad for missing out on few more details..
once we out of the main function... there are a couple more outsie of it which get executed... that is the problem.. this are mostly like your onclick listner and stuff...
since these buttons etc are part of main, it pops an error when the condition goes to the exit page...
Hope i waas able to explain it properly...
Click to expand...
Click to collapse
Now I get it! You can stop a method by calling return; or return val; if the method shall return anything. Note that if you are executing code for both layouts in more than one method you should check the condition every time or use a boolean instance variable with an if(condition) {code(); }else {code2();}
I am using one edit text view and one OK button to input a large amount of user data during a setup function but can't figure out how to pause the thread execution unit the OK button is pressed. I don't want to have to register and use a ton of different buttons and listeners to call individual functions for each user input and so far I've found out the hard way that a while look will lock the UI thread and running the loop in a separate thread will not make the program wait. Any Ideas?
public class SetupMenuActivity extends Activity
{
private TextView setupPrompt;
boolean okButtonPressed = false;
@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.setup_menu);
setup();
}
private OnClickListener okButtonListener = new OnClickListener()
{
@override
public void onClick(View v)
{
okButtonPressed = true;
}
};
private void setup()
{
Button okButton = (Button) findViewById(R.id.okButton);
okButton.setOnClickListener(okButtonListener);
setupPrompt = (TextView) findViewById(R.id.setupPrompt);
setupPrompt.setText("Please Enter Your Name");
// Make program wait for ok button clicked
setupPrompt.setText("Please Enter a Name for your Account");
}
}
What else could the user click/etc that you want to prevent from happening? If you want to block another button, then you can either do button.setClickable(false) or even button.setVisibility(View.GONE) until the ok button is clicked. Instead blocking the whole thread doesn't make much sense
The only two things the user can interact with is the button and the edit text box. I want to prevent the changing of the setupPrompt text view until the Ok button is pressed. The easy way to do it would be to put it into the onClickListener but there is a whole series of the prompts and waiting for user input so I'm trying to avoid creating a ton of different button listeners for each piece of user input.
TShipman1981 said:
The only two things the user can interact with is the button and the edit text box. I want to prevent the changing of the setupPrompt text view until the Ok button is pressed. The easy way to do it would be to put it into the onClickListener but there is a whole series of the prompts and waiting for user input so I'm trying to avoid creating a ton of different button listeners for each piece of user input.
Click to expand...
Click to collapse
The way you think this would work is not right, you have to think through it again, sorry . In Android, you can almost never wait for user events (because they might not happen). Instead, you have to do what you can during setup and everything that can only happen after a certain event has to be in the onEvent method (for instance onClick). What you can do to make it less complex is one method which is called only from the onClickListener. The method keeps track of how many times it has been called with an int step instance variable. That method has to execute what should happen at each step.
SimplicityApks said:
The way you think this would work is not right, you have to think through it again, sorry . In Android, you can almost never wait for user events (because they might not happen). Instead, you have to do what you can during setup and everything that can only happen after a certain event has to be in the onEvent method (for instance onClick). What you can do to make it less complex is one method which is called only from the onClickListener. The method keeps track of how many times it has been called with an int step instance variable. That method has to execute what should happen at each step.
Click to expand...
Click to collapse
Yeah Agreed with Simp. I would honestly make one method with all the info you need then get all the info and call it only when the button is clicked. If I knew a bit more of what your trying to accomplish I might be able to help you code it more efficiently.