jeongiin / Lookie_Android_Study

Lookie Android Part kotlin study
0 stars 0 forks source link

Fragment- ListFragment & DialogFragment #11

Open jeongiin opened 5 years ago

jeongiin commented 5 years ago
  1. ListFragment

class MainActivity : AppCompatActivity() {

var list_fragment = TestListFragment()

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    var tran = supportFragmentManager.beginTransaction()
    tran.replace(R.id.container, list_fragment)
    tran.commit()
}

}


- activity_main_xml

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:id="@+id/container">


- TextListFragment

import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter import android.widget.ListView import android.widget.TextView import androidx.fragment.app.ListFragment

// TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private const val ARG_PARAM1 = "param1" private const val ARG_PARAM2 = "param2"

/**

}


- fragment_test_list

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".TestListFragment">

<TextView
        android:text="TextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:textAppearance="@style/TextAppearance.AppCompat.Large"/>
<ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@android:id/list" />

jeongiin commented 5 years ago
  1. DialogFragment
    • AlertDialog 를 Frag로 만들어 사용할 수 있음
    • AlertDialog와 큰 차이는 없지만 협업하다 보면 Frag가 편한 부분이 있음
    • Dialog : 사용자에게 결정을 내리게 하거나 추가 정보를 입력하게 하는 부가적인 창