I have a form which renders, but when I click the submit button, I am not exactly sure how to get the results.
Here is my Activity class:
package com.problemio;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class AddProblemActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.add_problem);
final EditText problemName = (EditText) findViewById(R.id.problem_name);
String name = problemName.getText().toString();
final EditText problemText = (EditText) findViewById(R.id.problem_text);
String text = problemText.getText().toString();
System.out.println(name);
System.out.println(text);
// Button browseProblemsButton = (Button)findViewById(R.id.browseProblemsButton);
// Button searchProblemsButton = (Button)findViewById(R.id.searchProblemsButton);
// Button myProblemsButton = (Button)findViewById(R.id.myProblemsButton);
}
public void sendFeedback(View button)
{
System.out.println("3");
Button addProblemButton = (Button)findViewById(R.id.button_send_feedback);
addProblemButton.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
System.out.println("4");
//Intent myIntent = new Intent(ProblemioActivity.this, AddProblem.class);
//ProblemioActivity.this.startActivity(myIntent);
}
});
System.out.println("end");
// Do click handling here
}
}
I put some System.out statements in there to see if anything gets written to my log output, but that didn’t work. I am new to Android dev – is there a commonly used way to output things to the console?
I am also not sure where and how to get the input from the form elements.
Help appreciated,
Alex
Here’s how you get what even the user has input. You actually had all the code you needed in the first place, just not placed correctly. Your listener should look like this and be placed in the
onCreate()method (if I’m understanding your intentions correctly):Then your sendFeedback function would look like:
As @onit mentioned, you should use the Log class to print out debug information. Specifically Log.d().