2011-08-09 20 views
0

我有這個在我的第一個活動:在android中正確傳遞數據?

private AdapterView.OnItemClickListener _itemClickLis = new OnItemClickListener() 
    { 
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) 
    { 
     // Now we want to actually get the data location of the file 
     String [] proj={MEDIA_DATA}; 
     // We request our cursor again 
     _cursor = managedQuery(_contentUri, 
       proj, // Which columns to return 
       null,  // WHERE clause; which rows to return (all rows) 
       null,  // WHERE clause selection arguments (none) 
       null); // Order-by clause (ascending by name) 
     // We want to get the column index for the data uri 
     int count = _cursor.getCount(); 
     // 
     _cursor.moveToFirst(); 
     // 
     _columnIndex = _cursor.getColumnIndex(MEDIA_DATA); 
     // Lets move to the selected item in the cursor 
     _cursor.moveToPosition(position); 
     // And here we get the filename 
     String filename = _cursor.getString(_columnIndex); 
     //*********** You can do anything when you know the file path :-) 
     showToast(filename); 

     Intent i = new Intent("com.ave.EDITORSCREEN"); 
     i.putExtra("mnt/sdcard-ext", _ID); 
     startActivity(i); 

    } 

這不是完整的代碼,但作爲完整的代碼從SD卡收集所有的視頻縮略圖,並顯示他們沿着它們路徑的(在祝酒詞)。我希望能夠點擊縮略圖,並傳遞到下一個活動的數據進行播放,停止,暫停,等你能看到我在第一個活動傳遞的數據:

public class Editor extends Activity { 
ImageButton video1; 
int isClicked = 0; 
ImageButton audio; 
int isClicked1 = 0; 

    @Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.editor); 

    video1 = (ImageButton) findViewById(R.id.video1); 
    video1.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      if (isClicked == 0) { 
       video1.setImageResource(R.drawable.video_pressed); 
       isClicked = 1; 
      } else { 
       video1.setImageResource(R.drawable.video1); 
       isClicked = 0; 
      } 
      } 
    }); 

    audio = (ImageButton) findViewById(R.id.audio); 
    audio.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      if (isClicked1 == 0) { 
       audio.setImageResource(R.drawable.audio_pressed); 
       isClicked1 = 1; 
      } else { 
       audio.setImageResource(R.drawable.audio); 
       isClicked1 = 0; 
      } 
      } 
     }); 
    } 
} 

我想要得到的數據,我將需要把

String data = getIntent().getStringExtra("mnt/sdcard-ext"); 

但在哪裏的onCreate方法?或者,這是甚至正確的方式來獲得傳遞的數據?最後,我怎樣才能播放視頻?是否有某種說視頻播放器的代碼?如果是的話,我會把它放在我最後的活動中?

回答

1

您不必在onCreate()方法中做,但爲什麼不呢?你會把它放在哪裏?

如果您正在尋找任何類型的文件,我會建議檢查Android Developers Java(Android)Doc。一般來說,Android Developers有一個很棒的網站,全部都是關於Android的。我認爲這是一個開始使用Android Audio/Video is here的好地方。

通常,您可以在onCreate()中設置MediaPlayer界面(播放/暫停按鈕和視圖)的佈局,並設置您的點擊/觸摸偵聽器以在接收到輸入時執行。

對於第一門編程課程,看起來你做得很好。祝你好運!