2011-06-08 133 views
2

在我的應用程序列表視圖中列出所有視頻縮略圖與列表視圖中的描述。對於列表視圖模塊,我從http://android-er.blogspot.com/2010/06/custom-arrayadapter-with-with-different.html獲取代碼。吐司消息不顯示在列表視圖中

從鏈接我刪除代碼清單「星期日,星期一」和它有關。相反,我代碼列表視頻拇指釘如下。 如果我觸摸列表(屏幕),更改代碼後不會顯示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; 
    } 
} 
} 
+0

不,我完全刪除該String [] dayofweek。而不是我放置代碼獲取視頻縮略圖。就像我的問題一樣。請檢查它並幫助我。 – 2011-06-08 12:51:44

+0

是你從SD卡獲取圖像 – Pinki 2011-06-08 12:56:30

+0

我從SD卡獲取視頻縮略圖。 – 2011-06-08 12:57:23

回答

0

當你告訴敬酒什麼是selection價值?嘗試分配一個硬編碼的值以確保其正常工作。

+0

不顯示Toast消息,更改我的代碼後不會調用onListItemClick方法。在原始代碼中顯示週日,週一......請幫助我。 – 2011-06-08 12:55:12

+0

您必須在設置列表適配器之前初始化_videosId *。你可以在那裏發佈代碼嗎? – 2011-06-08 12:57:08

+0

請檢查我編輯的問題。我粘貼完整編碼,請幫助我。 – 2011-06-08 13:01:02

0

不要把「this」放在你的麪包裏,試着放一些東西,比如:getApplicationContext()或者getBaseContext()。