1

目前在从列表中选择一个项目时,我必须将所选项目移出视图以使光标移到其位置。我尝试使用 newView 和网上可用的所有教程,但仍然无法解决问题。我正在使用一个自定义的 SimpleCursorAdapter。

适配器:-

public class Custom_Adapter extends SimpleCursorAdapter {


 private Context mContext;
private Context appContext;
private int layout;
private Cursor cr;
private final LayoutInflater inflater;

public Custom_Adapter(Context context,int layout, Cursor c,String[] from,int[] to) {
    super(context,layout,c,from,to);
    this.layout=layout;
    this.mContext = context;
    this.inflater=LayoutInflater.from(context);
    this.cr=c;
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // TODO Auto-generated method stub
    super.bindView(view, context, cursor);


    TextView titleS=(TextView)view.findViewById(R.id.TitleSong);
    TextView artistS=(TextView)view.findViewById(R.id.Artist);
    int Title_index;
    int Artist_index;



        Title_index=cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
        Artist_index=cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST);
        titleS.setText(cursor.getString(Title_index));
        artistS.setText(cursor.getString(Artist_index));


     if(cursor.getPosition()==AllSongs.songPosition){
        if(AllSongs.isSongPaused!=true){
                         //change text view background color
        }
        else{
                           Do nothing
        }

     }
     else{
                     //Do nothing
     }

}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    // TODO Auto-generated method stub
    return inflater.inflate(R.layout.music_items, parent, false);
}


}

全歌类:-

public class AllSongs extends ListActivity {




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.allsongs);

    String sortOrder = MediaStore.Audio.Media.TITLE + " ASC"; //----->Use for all songs


    lv=getListView();

    String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";

     String[] projection = {
                MediaStore.Audio.Media._ID,
                MediaStore.Audio.Media.ARTIST,
                MediaStore.Audio.Media.TITLE,
                MediaStore.Audio.Media.DATA,
                MediaStore.Audio.Media.DISPLAY_NAME,
                MediaStore.Audio.Media.DURATION,

        };
        //query 

        musiccursor = this.managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,projection,selection,null,sortOrder);
        music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);

        count = musiccursor.getCount();
        int a[]= new int[]{R.id.TitleSong,R.id.Artist};


       Custom_Adapter adapter=new Custom_Adapter(this, R.layout.music_items, musiccursor, new String[]{MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST},a);



        lv.setAdapter(adapter); 

}

@Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
    }
 }
4

0 回答 0