반응형

출처: 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});



반응형
반응형

출처: http://jsryu.tistory.com/73


안드로이드에서 문자 보내기 구현 방법을 기록해 놓아요


나중에 까먹지 않게 ㅋㅋㅋㅋ


먼저 AndroidManifest.xml 파일에 권한을 추가해 주시구요.

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />


구현하고자 하는 코드에

아래 함수를 복사해서 붙여넣기 하면 준비 끝.


//-----------------------------------------------------------------------------------------------------------------------------------------

private void sendSMS(String phoneNumber, String message) {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);

//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver() {
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "알림 문자 메시지가 전송되었습니다.", Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
//-----------------------------------------------------------------------------------------------------------------------------------------

이제 필요한 곳에서 저 함수를 불러 쓰면 되겠죠?


예를들어 심술이에게 문자를 보내고 싶다면


sendSMS("01012345678", "심술아 밥해죠");


요렇게 호출하면 문자가 슝 간답니다.



출처: http://jsryu.tistory.com/73 [LIFE SKETCH]

반응형

+ Recent posts