在此先感謝您的幫助,我的代碼在文本文件中顯示並顯示在ListView中,我在文本字段中的一行中包含Name和youtube。將字符串轉換爲ArrayList
但我看着試圖做的是獲取文本文件中的youtube字符串,並將其傳遞給我的新Activity類作爲webview播放視頻 只是想知道如何做到這一點,我怎麼能通過這個字符串到我的模型類中的Setters爲了得到它的一個實例,我需要將字符串轉換爲ArrayListString嗎?
public class menuFragment extends ListFragment {
ArrayList<model> songList = new ArrayList<model>();
public String[] listSongs = new String[]{};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list_fragment, container, false);
loadSongs();
return view;
}
public void loadSongs() {
try {
Resources ResFiles = getResources();
InputStream ReadDbFile = ResFiles.openRawResource(R.raw.songs);
byte[] Bytes = new byte[ReadDbFile.available()];
ReadDbFile.read(Bytes);
String DbLines = new String(Bytes);
listSongs = DbLines.split(",");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, listSongs);
setListAdapter(adapter);
} catch (Exception e) {
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Intent i = new Intent(getActivity(), playVid.class);
model selectedSong = MainController.getInstance().getSongs().get(position);
i.putExtra("selectedSong", selectedSong);
startActivity(i);
}
public class model implements Serializable {
private String name;
private String url;
public model(String name, String url) {
this.name=name;
this.url = url;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl(){
return url;
}
public void setUrl(String url){
this.url = url;
}
public class MainController
{
private static MainController instance;
private ArrayList<model> songList;
private MainController()
{
this.songList = new ArrayList<model>();
}
public static MainController getInstance()
{
if(instance == null)
{
instance = new MainController();
}
return instance;
}
public void addFlight(String name, String singer, String url)
{
model f = new model(name,singer,url);
this.songList.add(f);
}
public ArrayList<model> getSongs()
{
return this.songList;
}
實例? – Simas
EdSheeran#http://www.youtube.com/watch?v = lp-EO5I60KA, – David