我正在尝试实现一个自定义的SimpleCursorAdapter,但问题是当我运行应用程序时,listView没有显示任何内容。为什么呢?以下是我的代码:
package com.messageHider;
import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class myAdapter extends SimpleCursorAdapter {
private Context appContext;
private int layout;
private Cursor mycursor;
public myAdapter(Context context, int layout, Cursor c, String[] from,int[] to) {
super(context, layout, c, from, to);
this.appContext=context;
this.layout=layout;
this.mycursor=c;
}
@Override
public int getCount() {
return 0;
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater=(LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView=inflater.inflate(layout, null, true);
ImageView imageViewVidIcon=(ImageView)convertView.findViewById(R.id.imageViewVidThumb);
imageViewVidIcon.setImageResource(R.drawable.videothumb);
ImageView imageViewPlayBtn=(ImageView)convertView.findViewById(R.id.imageViewPlaybtn);
imageViewPlayBtn.setImageResource(R.drawable.playbtn);
TextView textViewTitle=(TextView)convertView.findViewById(R.id.textViewVideoTitle);
String title=mycursor.getString(mycursor.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME));
textViewTitle.setText(title);
imageViewPlayBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(appContext, "It works", Toast.LENGTH_LONG).show();
}
});
return convertView;
}
}