기본 콘텐츠로 건너뛰기

[android] make number select dialog with DialogFragment

The DialogFragment class provides all the controls you need to create your dialog and manage its appearance, instead of calling methods on the Dialog object.


The DialogFragment class was originally added with Android 3.0 (API level 11), for older API this class is provided with the Support Library.

if use support library version & proguard,
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
should be added to proguard rule.

Create NumberPickerDialogFragment



Override onCreateDialog() method.

the returned Dialog will be shown when NumberPickDialogFragment instance call show() method.

for example in Activiry
when click "Show Number Picker Dialog"


Create NumberPicker


set NumberPickDialogFragment view with NumberPicker
now Dialog will be shown like this


Create Interface
Selected value will be handled by Activity that made the Dialog, so declare interface to pass the value.
this interface called when "OK" & "Cancel" clicked.
implement in Activity

when Show Number Pick Dialog button clicked


When OK clicked show text 100


Complete code

MainActivity.java
NumberPcikDialogFragment.java

댓글

이 블로그의 인기 게시물

Example of java class transform with java agent and BCI

Dynamic transform   예제 시나리오 원하는 작업  DB에 요청하는 모든 쿼리를 출력 작업 순서 Agent 작성 ClassFileTransformer 구현 Agent 작성 Java Agent 구성도 Manifest 파일 Manifest-Version: 1.0 Premain-Class: sample.bci.Agent Agent-Class: sample.bci.Agent Can-Redefine-Classes: True must be end with new line - http://docs.oracle.com/javase/tutorial/deployment/jar/modman.html Agent.java /** * example for bci with java agent */ package sample.bci; import java.lang.instrument.Instrumentation; /** * @author k * */ public class Agent { public static void premain(String args, Instrumentation inst) { inst.addTransformer(new JdbcQueryTransformer()); } public static void agentmain(String args, Instrumentation inst) { inst.addTransformer(new JdbcQueryTransformer()); } } JdbcQueryTransformer. java /** * example for bci with java agent */ package sample.bci; import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.IllegalClassFormatException; impor...

[android] RecyclerView with Cursor

RecyclerView is new in Android 5.0 (Lollipop) . To use with support library add compile 'com.android.support:recyclerview-v7:21.0.0' in build.gradle file dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.0' compile 'com.android.support:recyclerview-v7:21.0.0' } and import import android.support.v7.widget.RecyclerView; Get from layout xml RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycle_list); Plug in LayoutManager recyclerView.setLayoutManager(layoutManager); Create Adapter NameRecyclerAdapter mAdapter; ... mAdapter = new NameRecyclerAdapter(); Plug in Adapter recyclerView.setAdapter(mAdapter); NameRecyclerViewAdapter.java import android.database.Cursor; import android.support.v7.widget.RecyclerView; import android.view.ViewGroup; import android.widget.TextView; /** * * Recycler Adapter for TestDB...