我在创建 Listview 适配器时遇到问题,这是代码。
import com.actionbarsherlock.app.SherlockFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Recipes extends SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ListView recipelist = (ListView) getView().findViewById(R.id.recipe_drawer);
String[] items ={ getResources().getString(R.string.block),
getResources().getString(R.string.tool),
getResources().getString(R.string.support),
getResources().getString(R.string.veggie)
};
ArrayAdapter<String> adapt = new ArrayAdapter<String>(Recipes.this, R.layout.recipes_list_item, items);
recipelist.setAdapter(adapt);
View rootView = inflater.inflate(R.layout.recipes, container, false);
return rootView;
}
}
我得到的错误是ArrayAdapter<String> adapt = new ArrayAdapter<String>(Recipes.this, R.layout.recipes_list_item, items);
,它说
构造函数 ArrayAdapter(Recipes,int,String[]); 未定义。
我尝试将Recipes.this 更改为this,但仍然出现相同的错误。任何帮助,将不胜感激!