提交 2c93d76d 编写于 作者: lizhongyi_'s avatar lizhongyi_

Merge branch 'dev_lzy' into dev

* dev_lzy:
  native page 增加了 recycleview 示例
{
"dependencies": [
"androidx.recyclerview:recyclerview:1.0.0"
]
}
......@@ -28,6 +28,11 @@ import Class from 'java.lang.Class';
import Exception from 'java.lang.Exception';
import PackageManager from 'android.content.pm.PackageManager';
import ResolveInfo from 'android.content.pm.ResolveInfo';
import RecyclerView from 'androidx.recyclerview.widget.RecyclerView';
import TextView from 'android.widget.TextView';
import ViewGroup from 'android.view.ViewGroup';
import LayoutInflater from 'android.view.LayoutInflater';
import LinearLayoutManager from 'androidx.recyclerview.widget.LinearLayoutManager';
......@@ -171,6 +176,46 @@ class CustomThread extends Thread{
}
}
class FruitAdapter extends RecyclerView.Adapter<FruitAdapter.ViewHolder>{
mFruitList: Array<String>
constructor(param:Array<String>){
mFruitList = param
}
ViewHolder = class extends RecyclerView.ViewHolder {
fruitName:TextView;
constructor(view:View) {
super(view);
fruitName = view.findViewById(R.id.fruit_name) as TextView;
}
}
override onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): ViewHolder {
let view: View =
LayoutInflater.from(parent.context).inflate(R.layout.fruit_item, parent, false)
return ViewHolder(view)
}
override onBindViewHolder(holder: ViewHolder, position: Int) {
let fruit: String = mFruitList[position]
holder.fruitName.setText(fruit)
}
override getItemCount(): Int {
return mFruitList.size
}
}
class DemoActivity extends Activity{
constructor (){
......@@ -190,6 +235,12 @@ class DemoActivity extends Activity{
let btn_start_thread = findViewById<Button>(R.id.btn_start_thread);
btn_start_thread.setOnClickListener(new StartThreadListener());
let recyclerView = findViewById<RecyclerView>(R.id.recycler_view)
let layoutManager = LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
let fruitAdapter = FruitAdapter(arrayListOf("香蕉","苹果","大鸭梨"));
recyclerView.setAdapter(fruitAdapter);
}
}
......
......@@ -8,4 +8,12 @@
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启前台服务(应用包活)" android:id="@+id/btn_start_service_front"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注册屏幕状态广播监听" android:id="@+id/btn_start_screen_listen"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开启异步任务" android:id="@+id/btn_start_thread"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler_view">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fruit_name"/>
</LinearLayout>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册