在列表视图中不显示toast消息

时间:2011-06-08 12:35:35

标签: android android-layout

在我的应用程序列表视图中,我列出了所有视频缩略图和列表视图中的描述。对于列表视图模块,我从http://android-er.blogspot.com/2010/06/custom-arrayadapter-with-with-different.html获取代码。

从链接我删除代码列表“星期日,星期一”,它相关。相反,我编码列表视频拇指指甲如下。 如果我触摸列表(屏幕),则在更改代码后不会显示Toast消息。但会显示原始代码Toast消息。请帮我。 我的代码

public class AndroidList extends ListActivity {

private final static Uri MEDIA_EXTERNAL_CONTENT_URI = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
private final static String _ID = MediaStore.Video.Media._ID;
private final static String MEDIA_DATA = MediaStore.Video.Media.DATA;
private Cursor _cursor;
private int _columnIndex;
private Uri _contentUri;
private String[] _videosId;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _contentUri = MEDIA_EXTERNAL_CONTENT_URI;
    initVideosId();
    setListAdapter(new MyCustomAdapter(AndroidList.this, R.layout.row,_videosId));

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Log.e("video", "called");
    String selection = l.getItemAtPosition(position).toString();
    Toast.makeText(this, selection, Toast.LENGTH_LONG).show();
}

private void initVideosId() {
    try {
        String[] proj = { _ID };
        _cursor = managedQuery(_contentUri, proj, null, null, null);
        int count = _cursor.getCount();
        _columnIndex = _cursor.getColumnIndex(_ID);
        _videosId = new String[count];
        _cursor.moveToFirst();
        for (int i = 0; i < count; i++) {
            int id = _cursor.getInt(_columnIndex);
            _videosId[i] = String.valueOf(id);
            _cursor.moveToNext();
        }
    } catch (Exception ex) {
        Log.e("video", ex.getMessage().toString());
    }

}

public class MyCustomAdapter extends ArrayAdapter<String> {

    public MyCustomAdapter(Context context, int textViewResourceId,
            String[] objects) {
        super(context, textViewResourceId, objects);
        // TODO Auto-generated constructor stub
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        if (row == null) {
            LayoutInflater inflater = getLayoutInflater();
            row = inflater.inflate(R.layout.row, parent, false);
        }
        TextView textfilePath = (TextView) row.findViewById(R.id.FilePath);
        textfilePath.setText(_videosId[position]);
        ImageView imageThumbnail = (ImageView) row.findViewById(R.id.Thumbnail);

        Bitmap bmThumbnail;
        int ids;
        ids = Integer.parseInt(_videosId[position]);
        bmThumbnail = MediaStore.Video.Thumbnails.getThumbnail(getContentResolver(), ids,MediaStore.Video.Thumbnails.MICRO_KIND, null);
        imageThumbnail.setImageBitmap(bmThumbnail);

        return row;
    }
}
}

2 个答案:

答案 0 :(得分:0)

展示吐司时selection的价值是多少?尝试分配硬编码值以确保其有效。

答案 1 :(得分:0)

不要在你的吐司中放入“this”,尝试输入类似:getApplicationContext()或getBaseContext()。