运行程序之后,点击列表项没有任何反应,item里面的button全部改成view了,依旧没有效果
点击之后有测试输出的语句,logcat里面未显示
//包名省略
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.sheng.leisheng.R;
import com.sheng.adapter.MusicListAdapter;
import com.sheng.util.MediaUtil;
import com.sheng.util.Mp3Info;
import com.sheng.util.SongUtil;
public class TestSong extends Fragment implements OnItemClickListener {
private static final String TAG = "SongFragment";
private ListView lv;
private List<Mp3Info> mpis;
private Map<String, Object> maplist;
static TestSong newInstance(String s, Map<String, Object> map) {
TestSong newFragment = new TestSong();
final SerializableMap myMap=new SerializableMap();
myMap.setMap(map);
Bundle bundle = new Bundle();
bundle.putSerializable("map", myMap);
newFragment.setArguments(bundle);
return newFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "SongFragment-----onCreate");
Bundle args = getArguments();
Bundle bundle = getArguments();
SerializableMap serializableMap = (SerializableMap) bundle.get("map");
maplist =serializableMap.getMap();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
Log.d(TAG, "SongFragment-----onCreateView");
View view = inflater.inflate(R.layout.musiclist, container, false);
lv = (ListView) view.findViewById(R.id.listview1);
MusicListAdapter mla = new MusicListAdapter(getActivity().getApplicationContext(),getSongUtil());
lv.setAdapter(mla);
lv.setCacheColorHint(0);
lv.setOnItemClickListener(this);
return view;
}
public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
// TODO Auto-generated method stub
System.out.println("leisheng119");
Log.d(TAG, "onItemClick");
lv.setBackgroundResource(R.drawable.listbg2);
Intent intent = new Intent();
intent.setClass(getActivity(),PlayActivity.class);
intent.putExtra("id", position);
getActivity().startActivity(intent);
}
private ArrayList<SongUtil> getSongUtil(){
ArrayList<SongUtil> hcList = new ArrayList<SongUtil>();
mpis = MediaUtil.getMp3Infos(getActivity().getApplicationContext());
Mp3Info mpi ;
if(MediaUtil.getSongCount()==0){
for(int i=0;i<7;i++)
{
SongUtil c0 = new SongUtil();
c0.setAlbumphoto(R.drawable.music1+"");
c0.setSongName(maplist.get("songname")+"");
c0.setSinger(maplist.get("singer")+"");
c0.setDesc(R.drawable.love_normal+"");//设置未收藏模式的图标(按钮)
c0.setTabcard(R.drawable.tabcard+"");
hcList.add(c0);
}
}
else{
for(int i=0;i<mpis.size();i++)
{
mpi = mpis.get(i);
SongUtil c0 = new SongUtil();
c0.setAlbumphoto(R.drawable.music1+"");
c0.setSongName(mpi.getTitle()+"");
c0.setSinger(mpi.getArtist()+"");