我的HomeFragment上的EditText出现问题。我正在尝试在4个EditTexts(firstDigits,secondDigits,thirdDigits和fourthDigits)上输入IP地址,并将其显示在我的TextView(服务器)上。我的问题是,它不是在保存。 我还想让它显示在其他片段上。任何人? :(
public class HomeFragment extends Fragment implements View.OnClickListener {
TextView loggedName, loggedEmail, server;
UserLocalStore userLocalStore;
Button bConnect, bClear;
EditText firstDigits, secondDigits, thirdDigits, fourthDigits;
public HomeFragment() {
View v;
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_home, container, false);
server = (TextView) v.findViewById(R.id.server);
firstDigits = (EditText) v.findViewById(R.id.firstDigits);
secondDigits = (EditText) v.findViewById(R.id.secondDigits);
thirdDigits = (EditText) v.findViewById(R.id.thirdDigits);
fourthDigits = (EditText) v.findViewById(R.id.fourthDigits);
//loadSavedPreferences();
bConnect = (Button) v.findViewById(R.id.bConnect);
bConnect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (CheckNetwork.isInternetAvailable(getActivity())) //returns true if internet available
{
final TextView server = (TextView) getActivity().findViewById(R.id.server);
final EditText firstDigits = (EditText) getActivity().findViewById(R.id.firstDigits);
final EditText secondDigits = (EditText) getActivity().findViewById(R.id.secondDigits);
final EditText thirdDigits = (EditText) getActivity().findViewById(R.id.thirdDigits);
final EditText fourthDigits = (EditText) getActivity().findViewById(R.id.fourthDigits);
server.setText(firstDigits.getText().toString() + "." + secondDigits.getText().toString() + "."
+ thirdDigits.getText().toString() + "." + fourthDigits.getText().toString());
Toast.makeText(getActivity(), "Connected!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getActivity(), "No Connection", Toast.LENGTH_LONG).show();
}
}
});
bClear = (Button) v.findViewById(R.id.bClear);
bClear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final TextView server = (TextView) getActivity().findViewById(R.id.server);
final EditText firstDigits = (EditText) getActivity().findViewById(R.id.firstDigits);
final EditText secondDigits = (EditText) getActivity().findViewById(R.id.secondDigits);
final EditText thirdDigits = (EditText) getActivity().findViewById(R.id.thirdDigits);
final EditText fourthDigits = (EditText) getActivity().findViewById(R.id.fourthDigits);
server.setText("Device Network Address");
firstDigits.setText("");
secondDigits.setText("");
thirdDigits.setText("");
fourthDigits.setText("");
Toast.makeText(getActivity(), "Cleared!", Toast.LENGTH_LONG).show();
}
});
return v;
// Inflate the layout for this fragment
}
public void onClick(View v) {
}
}