0

Like we always use getText().toString(); to get String from EditText, So why i am facing problem, earlier i was using Activity and now just switched to Fragment, see Log:

 02-19 00:17:27.508: V/strDate..... >>>(1354): android.widget.EditText{b1ecd2c0 V.ED..CL ......I. 0,0-0,0 #7f080001 app:id/editTextToShowDate}

Fragment

@Override
   public View onCreateView(LayoutInflater inflater, ViewGroup container,
     Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.android_frag, container, false);
        final EditText editTextDate = (EditText) view.findViewById(R.id.editTextToShowDate);
        String strDate = editTextDate.getText().toString();
        Log.v("strDate..... >>>", strDate);
        return view;
 }
Sun
  • 6,768
  • 25
  • 76
  • 131
  • Is your editTextDate in your Fragment layout? is it null? It is null for sure as you are calling it right after creating it. Can you check this and also post more of the log cat? – Atul O Holic Feb 19 '14 at 05:58
  • please post your logcat –  Feb 19 '14 at 06:07

2 Answers2

2

You need to get the text from editText on button click event

String strDate = editTextDate.getText().toString();
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • oh my bad luck i forgot to use Button widget, anyways thanks i ticked it as useful and will accept after 12 minutes, silly mistake :( – Sun Feb 19 '14 at 05:58
  • please let me know how can i change Tab Indicator (Underline) color programmatically ? to change ActionBar background color i used setBackgroundDrawable(...) – Sun Feb 19 '14 at 06:21
  • @AbrahimNeil pls look @ https://developer.android.com/training/basics/actionbar/styling.html – Raghunandan Feb 19 '14 at 06:22
  • bro without using xml ? my mean programmatically ! – Sun Feb 19 '14 at 06:24
  • Again look for the api's in the docs which can help. and search on stackoverflow http://stackoverflow.com/questions/21847416/how-to-change-tab-indicator-color-programmatically – Raghunandan Feb 19 '14 at 06:24
1

You should populate the following code into onStart() not onCreateView().

final EditText editTextDate = (EditText) getView().findViewById(R.id.editTextToShowDate);
    String strDate = editTextDate.getText().toString();
Ksharp
  • 102
  • 3