有没有办法在不将类扩展到“ListFragment”的情况下做到这一点?我不想使用 Listfragments,因为那样我将不得不更改 myviewpager 适配器..但如果别无选择,我将不得不:( .我也尝试使用 Listfragments 但我无法使 listfragments 成为 viewpager 的一部分,换句话说,我无法在 viewpager 中填充 Listfragments,
这只是显示我如何填充片段的代码的一部分
List<Fragment> fragments = new Vector<Fragment>();
fragments.add(Fragment.instantiate(this, FragmentSongs.class.getName()));
fragments.add(Fragment.instantiate(this, FragmentArtists.class.getName()));
fragments.add(Fragment.instantiate(this, FragmentPlaylists.class.getName()));
fragments.add(Fragment.instantiate(this, FragmentAlbums.class.getName()));
ViewPagerAdapter adapter = new ViewPagerAdapter(super.getSupportFragmentManager(), fragments);
ViewPager pager = (ViewPager)super.findViewById(R.id.viewpager);
他们是否有任何并行代码可以用于列表片段?
here is the code:
package sourcecode.jazzplayer;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
class Mp3Filter implements FilenameFilter{
public boolean accept(File dir,String name)
{
return (name.endsWith(".mp3"))|| (name.endsWith(".Mp3")) ||(name.endsWith(".MP3"));//searching for the files
}
}
public class FragmentSongs extends Fragment {
private static final String Sd_Path=new String("/sdcard/");
//setting up the source path
//private MediaPlayer mp =new MediaPlayer();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// updatePlaylist() ;
//updatePlaylist();
View view = inflater.inflate(R.layout.fragment_a, container, false);
ListView SngList = (ListView) view.findViewById(R.id.SongList);
SongDetails Detail = null;
Context _c = null ;
ArrayList<SongDetails> Songinfo;
// AdapterView.AdapterContextMenuInfo info;
Songinfo = new ArrayList<SongDetails>();
File home=new File(Sd_Path);
if(home.listFiles(new Mp3Filter()).length>0)
{
for(File file:home.listFiles(new Mp3Filter()))
{
Detail.setSong(file.getName());
Detail.setArtist(file.getName());
Detail.setAlbum(file.getName());
Songinfo.add(Detail);
SngList.setAdapter(new CustomAdapter(Songinfo , _c));
}
}
return view;
} }
/*private void updatePlaylist()
{
SongDetails Detail = null ;
Context _c = null ;
ArrayList<SongDetails> Songinfo;
AdapterView.AdapterContextMenuInfo info;
Songinfo = new ArrayList<SongDetails>();
File home=new File(Sd_Path);
if(home.listFiles(new Mp3Filter()).length>0)
{
for(File file:home.listFiles(new Mp3Filter()))
{
Detail.setSong(file.getName());
Detail.setArtist(file.getName());
Detail.setAlbum(file.getName());
Songinfo.add(Detail);
SngList.setAdapter(new CustomAdapter(Songinfo , _c));
}
}
}
}
*/