1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| class BlankFragment : Fragment() { var ctx:Context? = null var mPosition:Int = 0 var mInageId:Int = 0 var mDesc:String = "" var title:String = ""
val colorNames = listOf<String>("红色","黄色","绿色","青色","蓝色") val colors = intArrayOf(Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE) var mSeq:Int = 0 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { ctx = activity if (arguments != null) { mPosition = arguments!!.getInt("position", 0) mInageId = arguments!!.getInt("image_id", 0) mDesc = arguments!!.getString("desc") title = arguments!!.getString("title") } val view = inflater.inflate(R.layout.show_info, container, false)
view.findViewById<ImageView>(R.id.imageView).setImageResource(mInageId) view.findViewById<TextView>(R.id.textView).text = mDesc view.findViewById<Button>(R.id.se).setOnClickListener { ctx!!.selector("选择颜色", colorNames) { mSeq = it
val intent = Intent(BlankFragment.EVENT) intent.putExtra("seq", it) intent.putExtra("color", colors[it]) ctx!!.sendBroadcast(intent) } } return view }
companion object { const val EVENT:String = "changeColor" fun newInstance(position:Int, image_id:Int, desc:String, title:String) : BlankFragment {
val fragment = BlankFragment() val bundle = Bundle() bundle.putInt("position", position) bundle.putInt("image_id", image_id) bundle.putString("desc", desc) bundle.putString("title", title) fragment.arguments = bundle return fragment } } }
|