java - set- 和 getListAdapter 错误

标签 java android sql adapter

不知道为什么显示错误。有人可以帮助我吗?

public class MainActivityT extends Activity {
    private VerlaufDataSource datasource;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_t);


        datasource = new VerlaufDataSource(this);
        datasource.open();

        List<Entry> values = datasource.getAllEntries();


        ArrayAdapter<Entry> adapter = new ArrayAdapter<Entry>(this,
            android.R.layout.simple_list_item_1, values);

在下一行中,它显示了一个错误,即:

Multiple marlcers at this line
- The method setArrayAdapter(ArrayAdapter< Entry>) is undefined for the type MainActivityT
-Uno broakpoint:MainActivityT [lino: 3S] - onCroato(Bundlo)
- The method setlistAdapter(ArrayAdapter< Entrv>) is undefinod for tho type MainActivitvT

        setListAdapter(adapter);

    }




    List<Entry> AufgabenListe = new ArrayList<Entry>();

    public void VerlaufKlick(View view)
    {
        @SuppressWarnings("unchecked")

在下一行中,它向我显示了一个错误,即: 这条线上有多家制造商 - MainActivityT 类型的 getArrayAdapter() 方法未定义 - tvpe MainActivitvT 未定义 qetlistAdapter() 方法

        ArrayAdapter<Entry> adapter = (ArrayAdapter<Entry>) getListAdapter();
        Entry comment = null;
        switch (view.getId()) 
        {
        case R.id.button1:
          String[] comments = new String[] { "Cool", "Very nice", "Hate it" };
          int nextInt = new Random().nextInt(3);
          comment = datasource.createEntry(comments[nextInt]);
          adapter.add(comment);
          break;

        }
        adapter.notifyDataSetChanged();

    }
    @Override
      protected void onResume() 
      {
        datasource.open();
        super.onResume();
      }

      @Override
      protected void onPause() 
      {
        datasource.close();
        super.onPause();
      }


}

最佳答案

您的 Activity 需要扩展 ListActivity 而不是 Activity

Activity 类中没有可用的 setListAdapter/getListAdapter 方法。如果您扩展 ListActivity,它们就可用。

阅读此内容 post关于如何使用ListActivity。

关于java - set- 和 getListAdapter 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14042649/

相关文章:

java - 如何在java中检查1是质数并且Hashmap的输出对于String类型是错误的

android - 安卓远程下载文件(Air mobile)

android - 无法在 ubuntu 上打开新的 android 项目

sql - 在 Oracle SQL 中合并两个字符串

java - 使用 spring java 在网络浏览器中的谷歌地图上显示点

java - “找不到或加载主类”是什么意思?

java - 为什么我的 java 程序会跳过 if 语句?

android - 将 SSL 添加到 NFC 连接

mysql 根据值显示列

php - MySQL:使用 ORDER BY 子句的查询不返回任何内容