我正在尝试从我的 Android 应用程序的 EditText 元素中获取 getText() 。这是我用来声明编辑文本的 Java I 代码:
public class LogFragment extends Fragment {
private AlertDialog mDialog;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View logView = inflater.inflate(R.layout.log_form, container, false);
final EditText raceName = (EditText) findViewById(R.id.EditTextName);
// Handle buttons here...
View logButton = logView.findViewById(R.id.ButtonLogRace);
logButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.logged_text);
builder.setCancelable(false);
builder.setPositiveButton(R.string.ok_label,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// develop georeferencing, shared preferences saving, automatic calculations and a results window
}
});
mDialog = builder.show();
}
});
return logView;
}
这是使用 xml 构建的 EditText:
<EditText
android:id="@+id/EditTextName"
android:layout_height="wrap_content"
android:hint="@string/racename"
android:inputType="textPersonName"
android:layout_width="fill_parent"
android:textSize="8pt">
</EditText>
为什么我会收到此错误:
error: cannot find symbol method findViewById(int)
最佳答案
试试这个
final EditText raceName = (EditText) logView .findViewById(R.id.EditTextName);
关于java - Android xml和Java : Get text from Edit Text,找不到符号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31332555/