0

hello guys seriously am new to android and please i would like you to help me with this code...to edit it

 public class LoginFragment extends Fragment implements OnClickListener {
private EditText login, password, domain;
private ImageView apply;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.setup_generic_login, container, false);

    login = (EditText) view.findViewById(R.id.setup_username);
    password = (EditText) view.findViewById(R.id.setup_password);
    domain = (EditText) view.findViewById(R.id.setup_domain);
    apply = (ImageView) view.findViewById(R.id.setup_apply);
    apply.setOnClickListener(this);

    return view;
}

@Override
public void onClick(View v) {
    int id = v.getId();

    if (id == R.id.setup_apply) {
        if (login.getText() == null || login.length() == 0 || password.getText() == null || password.length() == 0 || domain.getText() == null || domain.length() == 0) {
            Toast.makeText(getActivity(), getString(R.string.first_launch_no_login_password), Toast.LENGTH_LONG).show();
            return;
        }

        SetupActivity.instance().genericLogIn(login.getText().toString(), password.getText().toString(), domain.getText().toString());
    }
}}

i'd like to assign domain a default string, (like domain = "pearlcom.au.ug") i've edited the xml file and removed the EditText field

please don't close my post.......just ignore! thanks for those who are goin to help me!

Essiw Sined
  • 79
  • 1
  • 6
  • By `default string`, do you mean the [hint](http://stackoverflow.com/questions/4373888/android-edittext-hint)? – Phantômaxx Aug 20 '15 at 19:09
  • yeah by default.......i don't want users to enter it......i want it to be assigned to..... – Essiw Sined Aug 20 '15 at 19:52
  • 1
    Well if you mean a hint then use `android:hint="@string/somestring"` in your activity XML, and if you mean a default value then `editText.setText(@string/somestring);` – hoss Aug 20 '15 at 20:55

2 Answers2

1

you can just do:

android:text="@string/domain" and assign whatever domain string you choose in the strings.xml and you would have that as default.

-> If you want a placeholder displayed, please include

android:hint="@string/enter_domain"

Actiwitty
  • 1,232
  • 2
  • 12
  • 20
  • i don't want to be displaced – Essiw Sined Aug 20 '15 at 19:54
  • Do you just want it to be the same domain at all times? Then you can just remove the edittext altogether and assign the domain string in your java code and use that? – Actiwitty Aug 20 '15 at 19:56
  • something like: private String domain="pearlcom.au.ug"; and in onClick: SetupActivity.instance().genericLogIn(login.getText().toString(), password.getText().toString(), domain); Hope this helps. – Actiwitty Aug 20 '15 at 19:57
  • yeah i want it to be that all the time and i've removed the EditText in xml file – Essiw Sined Aug 20 '15 at 20:29
  • but i get error on this line " if (login.getText() == null || login.length() == 0 || password.getText() == null || password.length() == 0 || domain.getText() == null || domain.length() == 0) " that "getText()" can't be resolved – Essiw Sined Aug 20 '15 at 20:31
  • getText() is a TextView method and will throw an error as you are using a string. You can remove the 'domain.getText() == null || domain.length() ==0' piece as you are hard coding it anyway – Actiwitty Aug 20 '15 at 20:33
  • np..you can consider accepting the answer if it helped you – Actiwitty Aug 20 '15 at 22:32
0

Simply do this in onCreate():

domain.setText("pearlcom.au.ug");
Aakash
  • 5,181
  • 5
  • 20
  • 37
  • don't you think i need to change somewhere in private EditText login, password, domain; or remove the domain from EditText and i don't want the domain to be visible, because i've removed EditText field... – Essiw Sined Aug 20 '15 at 19:58
  • i need domain = "pearlcom.au.ug" be the same all the time and invisible to user cos i've already removed EditText in xml file now the java code – Essiw Sined Aug 20 '15 at 20:34