0

Android app Development for Dummiesで、コードの最後のビットの後にエラーが発生します。

この型のメソッドsetListAdapter(ArrayAdapter<String>)は未定義ですReminderListActivity

コードは次のとおりです。

package com.dummies.android.taskreminder;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class ReminderListActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reminder_list);

    String[] items = new String[] { "Foo", "Bar", "Fizz", "Bin"};
    ArrayAdapter<String> adapter =
      new ArrayAdapter<String>(this, R.layout.reminder_row, R.id.text1, items);
    setListAdapter(adapter);
  }
}
4

2 に答える 2

1

Activity持っていないように見えますsetListAdapter()が、そのサブクラスListActivityにはあります。多分あなたがしたい

public class ReminderListActivity extends ListActivity {

代わりは?これはうまくいくはずです:

package com.dummies.android.taskreminder;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class ReminderListActivity extends ListActivity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reminder_list);

    String[] items = new String[] { "Foo", "Bar", "Fizz", "Bin"};
    ArrayAdapter<String> adapter =
      new ArrayAdapter<String>(this, R.layout.reminder_row, R.id.text1, items);
    setListAdapter(adapter);
  }
}
于 2012-05-10T00:22:07.440 に答える
1

Activityメソッドを定義しませんsetListAdapter()ListActivity代わりに拡張したいと思います:

public class ReminderListActivity extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reminder_list);

        String[] items = new String[] { "Foo", "Bar", "Fizz", "Bin"};
        ArrayAdapter<String> adapter =
            new ArrayAdapter<String>(this, R.layout.reminder_row, R.id.text1, items);
        setListAdapter(adapter);
    }
}
于 2012-05-10T00:22:14.547 に答える