반응형

출처: http://elfinlas.tistory.com/221 [MHLab Blog]


EditText라는 녀석이 있는데 입력받은 Text를 표기하기 위해서는 다음과 같이 처리해준다.

 

EditText editText = (EditText)findViewById(R.id.editText);


editText.getText.toString();을 하면 String객체로 Text를 리턴하게 된다.

 

또한 이 String이 공백인지 아닌지를 체크하기 위해서는 다음과 같이 처리를 해줘도 된다.

 

if ( editText.getText.toString().length() == 0 ) {

//공백일 때 처리할 내용

} else {

//공백이 아닐 때 처리할 내용

 

으로 공백체크도 해줄 수 있다.



반응형
반응형

출처: http://kwangsics.tistory.com/entry/Android-Activity%EC%97%90%EC%84%9C-Fragment-%ED%95%A8%EC%88%98-%ED%98%B8%EC%B6%9C


프라그먼트를 사용하다 보면 Fragment에서 Activity 함수를 호출하는 경우, Activity에서 Fragment 함수를 호출하는 경우가 꽤나 있다.


1. Activity function call from Fragment

((MainActivity)getActivity()).testFunction();


2. Fragment function call from Activity

  2.1 findFragmentTag 이용

((FragmentB) getSupportFragmentManager().findFragmentByTag("fragmentTag")).testFunction();


  2.2 findFragmentById 이용

TestFragment tf = (TestFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container);
tf.testFunction();


Fragment 함수를 호출하는 경우는 findFragmentTag를 이용하는 방법과 findFragmentById를 이용하는 경우가 있다. 본인이 상황에 맞게 사용하면 될 것이다.


참조 사이트 : http://stackoverflow.com/questions/20825600/findfragmentbytag-returns-null-after-perform-a-fragmenttransaction-using-repla

http://stackoverflow.com/questions/12659747/call-an-activity-method-from-a-fragment



출처: http://kwangsics.tistory.com/entry/Android-Activity에서-Fragment-함수-호출 [린기린기린의 개인 기록 공간]

출처: http://kwangsics.tistory.com/entry/Android-Activity에서-Fragment-함수-호출 [린기린기린의 개인 기록 공간]

반응형
반응형
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle   savedInstanceState) {
   View view =  inflater.inflate(R.layout.secondefragment, container, false);
    mWebView = (WebView) view.findViewById(R.id.activity_main_webview);
   progressBar = (ProgressBar) view.findViewById(R.id.progressBar1);

   WebSettings webSettings = mWebView.getSettings();
   webSettings.setJavaScriptEnabled(true);
   mWebView.loadUrl("http://www.google.com");

   return view;


}




채택취소하기


반응형
반응형

 출처: http://pikac.tistory.com/169 [pikac]


// 영문만 허용 (숫자 포함)

protected InputFilter filter= new InputFilter() {

        public CharSequence filter(CharSequence source, int start, int end,

                                Spanned dest, int dstart, int dend) {


                Pattern ps = Pattern.compile("^[a-zA-Z0-9]+$");

                if (!ps.matcher(source).matches()) {

                        return "";

                } 

                return null;

        } 

}; 


// 한글만 허용

public InputFilter filterKor = new InputFilter() {

        public CharSequence filter(CharSequence source, int start, int end,

                                Spanned dest, nt dstart, int dend) {


                Pattern ps = Pattern.compile("^[ㄱ-가-힣]+$");

                if (!ps.matcher(source).matches()) {

                        return "";

                } 

                return null;

        } 

};

abcd.(EditText) findViewById(R.id.abcd);

abcd.setFilters(new InputFilter[] {filter});



반응형

+ Recent posts