Skip to content

Instantly share code, notes, and snippets.

View nein37's full-sized avatar

こやまカニ大好き nein37

  • Tokyo, Japan
View GitHub Profile
@Override
public void onClick(View v) {
HogeDialogFragment fragment = new HogeDialogFragment();
// 必要なパラメータがあればsetArgument
// requestCodeが37になる
fragment.setTargetFragment(null,37);
fragment.show(getFragmentManager(), "dialog");
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 指定したrequestCodeで戻ってくる
if (requestCode == 37)
Log.d("HogeDialogFragmentResult", Integer.toString(requestCode));
}
@nein37
nein37 / file0.java
Last active August 29, 2015 14:04
Fragment使用時のIllegalStateException回避 ref: http://qiita.com/nein37/items/32613e9acd9558566c5e
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
public class RefreshFragment extends Fragment implements
SwipeRefreshLayout.OnRefreshListener {
private SwipeRefreshLayout mSwipeRefreshLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.refreshlayout, null);
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipelayout);
@nein37
nein37 / file0.xml
Last active October 29, 2015 03:58
ActionBarの共有ボタンに共有履歴を表示する方法 ref: http://qiita.com/nein37/items/cf5af57f4a313958631d
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MyActivity">
<item
android:id="@+id/action_share_always"
android:actionProviderClass="android.widget.ShareActionProvider"
android:showAsAction="always"
android:title="@string/action_share" />
</menu>
@nein37
nein37 / MyActivity.java
Created August 10, 2014 09:27
PopupWindowで画面内にダイアログ風の表示をする方法 ref: http://qiita.com/nein37/items/cc4fe1dc4f9527f8dd59
private PopupWindow mPopupWindow;
@Override
public void onClick(View v) {
mPopupWindow = new PopupWindow(MyActivity.this);
// レイアウト設定
View popupView = getLayoutInflater().inflate(R.layout.popup_layout, null);
@nein37
nein37 / file0.java
Created August 11, 2014 02:04
BroadcastReceiverの処理結果を受け取る方法 ref: http://qiita.com/nein37/items/b50022a5c44546064437
BroadcastReceiver receiver = new MyBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(MY_ACTION);
// 優先度を高めに設定
intentFilter.setPriority(100);
registerReceiver(receiver, intentFilter);
@nein37
nein37 / AndroidManifest.xml
Last active February 9, 2016 09:37
スリープ時にもBroadcastを処理する方法 ref: http://qiita.com/nein37/items/52523e39932323ebc654
<uses-permission android:name="android.permission.WAKE_LOCK" />
<receiver android:name=".MyBroadcastReceiver">
...
</receiver>
<service android:name=".MyService" />
@nein37
nein37 / SlidingPanelFragment.java
Last active August 29, 2015 14:05
マルチペインレイアウトを簡単に実装する方法 ref: http://qiita.com/nein37/items/d3a5e4b016a1251cfad7
public class SlidingPanelFragment extends Fragment {
SlidingPaneLayout mSlidingPaneLayout;
public SlidingPanelFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@nein37
nein37 / file0.java
Created August 14, 2014 15:25
安全にファイルを操作する ref: http://qiita.com/nein37/items/f50ab4fd39c3fdb8498a
AtomicFile atomicFile = new AtomicFile(getFileStreamPath(FILENAME));
FileOutputStream fos = null;
try {
// 書き込み開始
fos = atomicFile.startWrite();
fos.write(...);
// 書き込み成功
atomicFile.finishWrite(fos);