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

How to get string from an EditText?

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);

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


 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() {
      public void onClick(View v) {

    return view;

 public void buttonClicked(View view) {
 } }
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