我正在尝试制作一个程序,该程序接受用户文本输入并将其显示在文本视图中,同时还根据已选中的单选按钮和/或复选框进行格式化。
这是我的 mainactivity.java 的完整代码
包 com.example.lab3_lefelhocz;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.*;
import android.graphics.Color;
public class MainActivity extends Activity {
TextView messageTextView;
EditText inputEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.radioBlack:
if (checked)
// Text is black.
messageTextView.setTextColor(Color.BLACK);
break;
case R.id.radioBlue:
if (checked)
// Text is blue.
messageTextView.setTextColor(Color.BLUE);
break;
case R.id.radioRed:
if(checked)
// Text is red.
messageTextView.setTextColor(Color.RED);
break;
}
}
public void inputEditText(View view) {
if (inputEditText.getText().toString().equals("")) {
String editTextValue = inputEditText.getText().toString();
messageTextView.setText(editTextValue);
} else {
inputEditText.setText("");
messageTextView.setText("");
}
}
}