万能adapter链接 0
// 万能adapter
implementation 'com.zhy:base-rvadapter:3.0.3'
implementation 'com.zhy:base-adapter:3.0.3'
1TestListViewActivity
package com.ruhai.yibei.test;
import android.os.Bundle;
import android.widget.ListView;
import com.ruhai.yibei.R;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;
import java.util.ArrayList;
import java.util.List;
import androidx.appcompat.app.AppCompatActivity;
public class TestListViewActivity extends AppCompatActivity {
private ListView mTestLv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//todo 使用listview header 方式实现热门服务界面
setContentView(R.layout.activity_test_list_view);
List<String> mStrings = new ArrayList<>();
for (int i = 'A'; i <= 'Z'; i++) {
mStrings.add("当前是数据--------------->" + (char) i);
}
mTestLv = (ListView) findViewById(R.id.test_lv);
mTestLv.setAdapter(new CommonAdapter<String>(this, R.layout.item_list, mStrings)
{
@Override
protected void convert(final ViewHolder viewHolder, final String item, final int position) {
viewHolder.setText(R.id.id_item_list_title, item);
}
});
}
}
2 activity_test_list_view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".test.TestListViewActivity">
<ListView
android:id="@+id/test_lv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
|