0

我有一个哈希图,我正在加载到一个简单的适配器中

public static ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String,    String>>();

....
    musiclist = (TextView) getView().findViewById(R.id.checkTextView);
    filelv = (ListView)getView().findViewById(R.id.FileList);
    filelv.setItemsCanFocus(false);
    filelv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);

    //if (trackcount>previousTrackCount){
    ListAdapter playlistadapter = new SimpleAdapter(getActivity().getApplicationContext(), songsList, R.layout.file_view,
                new String[] { "songTitle","songAlbum", "songPath" }, new int[] { R.id.checkTextView, R.id.text2, R.id.text3 });
    filelv.setAdapter(playlistadapter);

这完美地工作,给我在我的列表视图中显示的所有三个值。

但是...我希望能够连接字符串,以便每个列表项的第二行如下

songAlbum(songArtist)

例如,有注意左输(Foo Fighters)

当我将 ListAdapter 更改为以下内容时,第二行只是空白

ListAdapter playlistadapter = new SimpleAdapter(getActivity().getApplicationContext(), songsList, R.layout.file_view,
                new String[] { "songTitle","songAlbum" + "(" + "songArtist" + ")", "songPath" }, new int[] { R.id.checkTextView, R.id.text2, R.id.text3 });

我已经测试了所有字符串以确保它们包含数据。

请提出建议!

4

1 回答 1

0

您将不得不添加另一个文本框。并使用下面的代码..当然,您将必须拥有一个包含所有 4 个键的哈希图。

SimpleAdapter playlistadapter = new SimpleAdapter(getActivity().getApplicationContext(), songsList, R.layout.file_view,
                new String[] { "songTitle","songAlbum", "songartist","songPath" }, new int[] { R.id.checkTextView, R.id.text2, R.id.text3, R.id.text4 });

playlistadapter.setViewBinder(new SimpleAdapter.ViewBinder(){
    boolean setViewValue(View view, Object data, String textRepresentation){
            if(view.getId () == R.id.songartist){
                view.setText("("+textRepresentation+")");
            }
    }
});
于 2012-09-15T17:10:08.847 回答