代码:
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class Main8Activity extends AppCompatActivity {
private ListView listview;
private List<String> list = new ArrayList<String>();
private MyAdapter adapter;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main8);
btn = (Button) findViewById(R.id.btn);
listview = (ListView) findViewById(R.id.listview);
for (int i = 0; i < 18; i++) {