Home How to get string from an EditText?
Reply: 0

How to get string from an EditText?

user1248
1#
user1248 Published in April 22, 2018, 6:50 am

At the bottom of "buttonClicked" function I am trying to get the string from my EditText but it says "can't resolve "number". I don't understand why it can't.

public class TopFragment extends Fragment {
 TopFragmentListener activityListener;

public interface TopFragmentListener{
    void createFrament(String numberOfFragments);
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
   try{
        activityListener = (TopFragmentListener) context;
    }catch (ClassCastException e){
        throw new ClassCastException (context.toString());
    }

}

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

     final Button btnAdd = view.findViewById(R.id.btnAdd);
     EditText number = view.findViewById(R.id.number);
   btnAdd.setOnClickListener(new View.OnClickListener() {
        @Override
      public void onClick(View v) {
            buttonClicked(v);
        }
     });

    return view;
 }

 public void buttonClicked(View view) {
     activityListener.createFrament(number.getText);
 } }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313581 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO