SherlockListFragment中的listAdapter

时间:2013-08-07 10:40:46

标签: android android-listview actionbarsherlock

我想设置一个ListView,但希望活动属于Sherlock标签。

这是我的代码

public class PlayListActivity extends SherlockListFragment{
    // Songs list
    public ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

    @Override
    public SherlockFragmentActivity getSherlockActivity() {
        return super.getSherlockActivity();
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Get the view from fragmenttab3.xml
        View view = inflater.inflate(R.layout.playlist, container, false);
        ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();

        SongsManager plm = new SongsManager();
        // get all songs from sdcard
        this.songsList = plm.getPlayList();

        // looping through playlist
        for (int i = 0; i < songsList.size(); i++) {
            // creating new HashMap
            HashMap<String, String> song = songsList.get(i);

            // adding HashList to ArrayList
            songsListData.add(song);
        }

        // Adding menuItems to ListView

        ListAdapter Ladapter = new SimpleAdapter(this, songsListData,
                R.layout.playlist_item, new String[] { "songTitle" }, new int[] {
                        R.id.songTitle });

我在声明ListAdapter时遇到上面的错误,它说SimpleAdapter是未定义的。 当类扩展ListActivity时它工作得很好但是因为我想要标签并且滑动我扩展了sherlockListActivity我想这个类在Sherlock中不可用 有什么方法吗?

1 个答案:

答案 0 :(得分:0)

如果您没有使用片段,请从SherlockListActivity其他地方扩展您的活动 从SherlockFragmentActivity扩展您的活动类并添加SherlockListFragment片段。