我創建了兩個類,實際上它們都擴展了Activity。我想要做的是從第二類調用一個方法。來自Android上另一個類的調用方法
我想要做的是從第二類調用方法,然後在第一類中實現,不幸的是我沒有成功。
我需要你的幫助來解決這個問題。謝謝
我的第一類:
package com.math4kids;
import android.app.Activity;
import android.os.Bundle;
public class testing002 extends Activity {
private Sounds myotherclass;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.numeracy);
myotherclass.Randomsoundforrightanswer();
}
}
第二類:
package com.math4kids;
import java.util.Random;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
public class Sounds extends Activity {
MediaPlayer cool, good, perfect, sweet, excellent, goodthinking, greatjob,
notbad, thatstheway, youdidit, yes, again, wrong, sorry,
sundfornum01, sundfornum02;
public Random random = new Random();
public Sounds(Context context){
super.getApplicationContext();
}
public void Randomsoundforrightanswer() {
cool = MediaPlayer.create(this, R.raw.cool);
good = MediaPlayer.create(this, R.raw.good);
perfect = MediaPlayer.create(this, R.raw.perfect);
sweet = MediaPlayer.create(this, R.raw.sweet);
excellent = MediaPlayer.create(this, R.raw.excellent);
goodthinking = MediaPlayer.create(this, R.raw.goodthinking);
greatjob = MediaPlayer.create(this, R.raw.greatjob);
notbad = MediaPlayer.create(this, R.raw.notbad);
thatstheway = MediaPlayer.create(this, R.raw.thatstheway);
youdidit = MediaPlayer.create(this, R.raw.youdidit);
yes = MediaPlayer.create(this, R.raw.yes);
switch (random.nextInt(11)) {
case 0:
cool.start();
break;
case 1:
good.start();
break;
case 2:
perfect.start();
break;
case 3:
sweet.start();
break;
case 4:
excellent.start();
break;
case 5:
goodthinking.start();
break;
case 6:
greatjob.start();
break;
case 7:
notbad.start();
break;
case 8:
thatstheway.start();
break;
case 9:
youdidit.start();
break;
case 10:
yes.start();
break;
}
}
}
爲什麼你創造了大量只使用整數數組或ArrayList中存儲的文件編號,並根據隨機數 –
我知道如何做到這一點 –
分配給MediaPlayer的實例MediaPlayer的情況,但這是不是如果然後ü知道它的問題 –