我想在 Android Studio 中创建一个列表,但在这一行不断收到错误“适配器视图是抽象的,无法启动”。AdapterView arrayAdapter = new AdapterView (this, android.R.layout.simple_list_item_1, family );我该如何解决?代码在这里:package com.example.mylist;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.widget.AdapterView;import android.widget.ListAdapter;import android.widget.ListView;import java.util.ArrayList;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView MyList = (ListView) findViewById(R.id.MyList); ArrayList family = new ArrayList(); family.add("Abc"); family.add("Def"); family.add("Ghi"); AdapterView arrayAdapter = new AdapterView (this, android.R.layout.simple_list_item_1, family ); MyList.setAdapter((ListAdapter) arrayAdapter); }}
2 回答
jeck猫
TA贡献1909条经验 获得超7个赞
尝试这个
ArrayList<String> family = new ArrayList<String>();
family.add("Abc");
family.add("Def");
family.add("Ghi");
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,family );
MyList.setAdapter(arrayAdapter);
添加回答
举报
0/150
提交
取消
