0

Here is my activity's code

public class MainActivity extends Activity {
    String height, weight;
    String dob, dov;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    final Button button = (Button) findViewById(R.id.button1);

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            enterClicked();
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public void enterClicked()
{
    height = ((EditText) findViewById(R.id.editText1)).getText().toString();
    weight = ((EditText) findViewById(R.id.editText2)).getText().toString();
    System.out.println( height + " " + weight );
}
}

When I run this code on the emulator I want it to take in the text I input and when I click the button I want it to retrieve the text and print it in the log. It doesn't currently print. I don't have any pre-compile errors and it appears my links to my EditTexts are successful. What might be the issue?

4

3 回答 3

0

您可以使用LogToast。这些是最好的方法:

  1. Log.i("Display TextView check", height + " " + weight);

  2. Toast.makeText(getApplicationContext(), "Text check:" + height + " " + weight, Toast.LENGTH_LONG).show();

于 2013-07-23T17:52:58.050 回答
0

您不能将 System.out.println 用于 Android 应用程序。看到这个问题:为什么“System.out.println”在 Android 中不起作用?

于 2013-07-23T17:05:07.830 回答
0

考虑Log用于此目的。它为许多场景提供了日志记录选项。您可以根据日志消息的性质来引导和隔离日志消息。例子:

〜调试:

Log.d(String tag, String msg)

〜Info Log.i(字符串标签,字符串味精)

…………

在您的情况下,您可以这样使用 Log.i :

Log.i("MainActivity", height + " " + weight);

输出将在视图logcat下可用。info

您可以在Log此处阅读课程提供的选项:链接

于 2013-07-23T17:18:16.587 回答