我正在尝试从我的Android应用程序的EditText元素中获取文本()。这是我用来声明编辑文本的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)
答案 0 :(得分:2)
试试这个
final EditText raceName = (EditText) logView .findViewById(R.id.EditTextName);
答案 1 :(得分:0)
尝试创建一个更不含糊的代码
final EditText race name = (EditText) logView .findViewById(R.id.EditTextName);
还投射按钮
Button buttonedup= (Button) logView .findViewById(R.id.b1);