当相应的单选按钮被选中/选中并且按下按钮时,它不会获得EditText文本?
问题描述:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
viewRoot = inflater.inflate(R.layout.fragment_messages, container, false);
RelativeLayout relativeLayout = (RelativeLayout) viewRoot.findViewById(R.id.msg_fragment);
final RadioGroup radioGroup = (RadioGroup) viewRoot.findViewById(R.id.radio_grp);
final RadioButton rb2 = (RadioButton) viewRoot.findViewById(R.id.rb_msg2);
final RadioButton rb3 = (RadioButton) viewRoot.findViewById(R.id.rb_msg3);
final RadioButton rb4 = (RadioButton) viewRoot.findViewById(R.id.rb_msg4);
final EditText editText = (EditText) viewRoot.findViewById(R.id.et_customMsg);
final RadioButton rb1 = (RadioButton) viewRoot.findViewById(R.id.rb_msg1);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.rb_msg1){
str_rbText = rb1.getText().toString();
editText.setVisibility(View.INVISIBLE);
editText.setText("");
Log.e("RadioButton1 Text", str_rbText);
} else if (checkedId == R.id.rb_msg2){
str_rbText = rb2.getText().toString();
editText.setVisibility(View.INVISIBLE);
editText.setText("");
} else if (checkedId == R.id.rb_msg3){
str_rbText = rb3.getText().toString();
editText.setVisibility(View.INVISIBLE);
editText.setText("");
} else if (checkedId == R.id.rb_msg4){
str_rbText = rb4.getText().toString();
editText.setVisibility(View.INVISIBLE);
editText.setText("");
} else if (checkedId == R.id.rb_customMsg){
editText.setVisibility(View.VISIBLE);
str_rbText = editText.getText().toString().trim();
//editText.setBackgroundDrawable(null); //to remove underline of EditText
Log.e("RadioButton 5", str_rbText);
}
}
});
Button btnSet = (Button) viewRoot.findViewById(R.id.btn_set_msgFrag);
btnSet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getContext(), "Set", Toast.LENGTH_SHORT).show();
//Log.e("Selected Msg",str_rbText);
}
});
return viewRoot;
}[Java Code][1]
答
您的logcat谈论了textView
。但是你的代码片段中没有TextView!你不是要留下什么!
你的editText
,我认为你最好先从setText("")
开始,然后再隐藏它。
请更加具体。 [见此](https://stackoverflow.com/help/how-to-ask)。 –
该问题不提供任何信息。请尝试描述您的问题,并提供异常/错误消息(如果有)。解释你已经尝试了什么等等。 –
好的。以下是logcat错误:08-28 00:44:06.030 23750-23750/com.nomanarif.navexample E/textview:initAddtionalStyle默认 08-28 00:45:14.650 23750-23750/com.nomanarif.navexample E/SpannableStringBuilder :SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有零长度 –