package com.example.myapplication; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import com.example.myapplication.core.BaseAnnotationActivity; import com.example.myapplication.core.annon.BindView; import java.util.LinkedList; /** * @Author lyr * @create 2020/9/24 14:02 */ @BindView(view = R.layout.app_content) public class ContentActivity extends BaseAnnotationActivity implements View.OnClickListener { // @BindView(view = R.id.tabLayout) // TabLayout tabLayout; @BindView(view = R.id.app_content_list) ListView listView; @BindView(view = R.id.btn_add) Button btnAdd; LinkedList<String> data = new LinkedList<>(); /** * 自定义回调 */ @Override protected void onCreateCustom() { // btnBack.setOnClickListener(this); data.add("666"); data.add("abc"); data.add("456"); ArrayAdapter<String> adapter = new ArrayAdapter<>( this, R.layout.content_item, data); // TabLayout tabLayout = findViewById(R.id.tabLayout); listView.setAdapter(adapter); btnAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { data.add("66,你点击了一下"); adapter.notifyDataSetChanged(); } }); } /** * Called when a view has been clicked. * * @param v The view that was clicked. */ @Override public void onClick(View v) { // switch (v.getId()) { // case R.id.app_content_back: { // jumpPage(MainActivity.class); // break; // } // } } }
item.xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView" android:layout_marginTop="100dp" android:layout_marginLeft="70dp" android:layout_marginStart="70dp"/>content.xml
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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"> <TableRow android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/tableRow" android:layout_marginTop="1dp" android:layout_marginBottom="1dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toTopOf="@+id/app_content_list" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="1dp" android:layout_marginStart="1dp" android:layout_marginEnd="1dp" android:layout_marginRight="1dp"> <Button android:text="append" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btn_add" /> </TableRow> <ListView android:layout_width="0dp" android:layout_height="0dp" android:id="@+id/app_content_list" app:layout_constraintTop_toBottomOf="@+id/tableRow" android:layout_marginBottom="1dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="1dp" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginStart="1dp" android:layout_marginEnd="1dp" android:layout_marginRight="1dp"/> </androidx.constraintlayout.widget.ConstraintLayout>