I'm working on an Android app, most of it was with the help of tutorials and reading material, my app is somewhat basic, make some calculations and display the result to the user
What I have
I created a fragment guided by this tutorial and I just replaced the button and textview with my own EditText and Button
I have an EditText, a Button, and a TextView, these are the widgets the user see when the fragment is opened
My goal
I want the user to input values in the EditText and when s/he click the button the TextView displays the result of some calculations
What I did
I've been trying some other answers from here, here, here, here, but I don't know how to wire up the code, every time I write some pieces of code my app crashes and I don't know what else to do
Here is my code
public class Circle_Perimeter extends Fragment
{
EditText edtxt;
Button btn;
TextView txt;
public static Circle_Perimeter newInstance()
{
Circle_Perimeter fragment = new Circle_Perimeter();
return fragment;
}
public Circle_Perimeter()
{
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_circle__perimeter,container,false);
edtxt = (EditText)rootView.findViewById(R.id.editText);
btn = (Button)rootView.findViewById(R.id.button6);
txt = (TextView) rootView.findViewById(R.id.textView6);
btn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
}
});
return rootView;
}
}
Question
How and where do I write the necessary code to make the EditText send a Toast warning the user the EditText is empty? or disable the Button if the EditText is empty?
EDIT: Really?? A downvote?? Instead of downvoting... Just give a warning or something else
EDIT 2: I already said that I did follow another answers from here and I couldn't make my code work that's why I'm here looking for an answer WITH my piece of code