動作するようになりましたが、思ったよりも長くなります。 新しい Java:
package com.example.musicbynumbers;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
public class majorScales extends Activity implements View.OnClickListener {
Button aflatmaj, amaj, bflatmaj, bmaj, cmaj, dflatmaj, dmaj, eflatmaj, emaj, fmaj, fsharpmaj, gmaj;
ImageButton mainMenu;
Intent j;
String scaleName;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.majorscales);
j = new Intent(this, display.class);
mainMenu = (ImageButton) findViewById(R.id.imagelogo);
aflatmaj = (Button) findViewById(R.id.aflatmajb);
amaj = (Button) findViewById(R.id.amajb);
bflatmaj = (Button) findViewById(R.id.bflatmajb);
bmaj = (Button) findViewById(R.id.bmajb);
cmaj = (Button) findViewById(R.id.cmajb);
dflatmaj = (Button) findViewById(R.id.dflatmajb);
dmaj = (Button) findViewById(R.id.dmajb);
eflatmaj = (Button) findViewById(R.id.eflatmajb);
emaj = (Button) findViewById(R.id.emajb);
fmaj = (Button) findViewById(R.id.fmajb);
fsharpmaj = (Button) findViewById(R.id.fsharpmajb);
gmaj = (Button) findViewById(R.id.gmajb);
mainMenu.setOnClickListener(this);
aflatmaj.setOnClickListener(this);
amaj.setOnClickListener(this);
bflatmaj.setOnClickListener(this);
bmaj.setOnClickListener(this);
cmaj.setOnClickListener(this);
dflatmaj.setOnClickListener(this);
dmaj.setOnClickListener(this);
eflatmaj.setOnClickListener(this);
emaj.setOnClickListener(this);
fmaj.setOnClickListener(this);
fsharpmaj.setOnClickListener(this);
gmaj.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.imagelogo:
Intent i = new Intent(majorScales.this, MainMenu.class);
startActivity(i);
break;
case R.id.aflatmajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.amajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.bflatmajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.bmajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.cmajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.dflatmajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.dmajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.eflatmajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.emajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.fmajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.fsharpmajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.gmajb:
scaleName = "aflatmaj";
j.putExtra("key", scaleName);
startActivity(j);
break;
}
}
}
package com.example.musicbynumbers;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.ImageView;
public class display extends Activity {
ImageView displayScale;
ImageButton logoButton;
String gotScale;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.display);
Initalize();
gotScale = getIntent().getStringExtra("key");
ImageView displayScale = (ImageView) findViewById(R.id.displayImage);
int id = getResources().getIdentifier("com.example.musicbynumbers:drawable/" + gotScale, null, null);
displayScale.setImageResource(id);
}
private void Initalize() {
// TODO Auto-generated method stub
displayScale = (ImageView) findViewById(R.id.displayImage);
logoButton = (ImageButton) findViewById(R.id.imagelogo);
gotScale = "ic_launcher.png";
}
}
ID名を取得して文字列に入れてから、別のアクティビティに移動して、対応するファイル名でリソース画像を開こうとしています
例えば。
r.id.x x を取得して文字列 y に入れ、別のアクティビティに送信する x を取得して文字列に入れるにはどうすればよいですか?
私はプログラミングに非常に慣れていないので、これには簡単な答えがあることを知っています。
package com.example.musicbynumbers;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
public class majorScales extends Activity implements View.OnClickListener {
Button aflatmaj, amaj, bflatmaj, bmaj, cmaj, dflatmaj, dmaj, eflatmaj, emaj, fmaj, fsharpmaj, gmaj;
ImageButton mainMenu;
Intent j;
String scaleName;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.majorscales);
j = new Intent(this, display.class);
mainMenu = (ImageButton) findViewById(R.id.imagelogo);
aflatmaj = (Button) findViewById(R.id.aflatmajb);
amaj = (Button) findViewById(R.id.amajb);
bflatmaj = (Button) findViewById(R.id.bflatmajb);
bmaj = (Button) findViewById(R.id.bmajb);
cmaj = (Button) findViewById(R.id.cmajb);
dflatmaj = (Button) findViewById(R.id.dflatmajb);
dmaj = (Button) findViewById(R.id.dmajb);
eflatmaj = (Button) findViewById(R.id.eflatmajb);
emaj = (Button) findViewById(R.id.emajb);
fmaj = (Button) findViewById(R.id.fmajb);
fsharpmaj = (Button) findViewById(R.id.fsharpmajb);
gmaj = (Button) findViewById(R.id.gmajb);
mainMenu.setOnClickListener(this);
aflatmaj.setOnClickListener(this);
amaj.setOnClickListener(this);
bflatmaj.setOnClickListener(this);
bmaj.setOnClickListener(this);
cmaj.setOnClickListener(this);
dflatmaj.setOnClickListener(this);
dmaj.setOnClickListener(this);
eflatmaj.setOnClickListener(this);
emaj.setOnClickListener(this);
fmaj.setOnClickListener(this);
fsharpmaj.setOnClickListener(this);
gmaj.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.imagelogo:
Intent i = new Intent(majorScales.this, MainMenu.class);
startActivity(i);
break;
case R.id.aflatmajb:
scaleName =
startActivity(j);
break;
case R.id.amajb:
startActivity(j);
break;
case R.id.bflatmajb:
startActivity(j);
break;
case R.id.bmajb:
startActivity(j);
break;
case R.id.cmajb:
startActivity(j);
break;
case R.id.dflatmajb:
startActivity(j);
break;
case R.id.dmajb:
;
startActivity(j);
break;
case R.id.eflatmajb:
;
startActivity(j);
break;
case R.id.emajb:
;
startActivity(j);
break;
case R.id.fmajb:
;
startActivity(j);
break;
case R.id.fsharpmajb:
;
startActivity(j);
break;
case R.id.gmajb:
;
startActivity(j);
break;
}
}
}
たとえば、「R.id.aflatmajb」のスイッチの場合、r.id の後の部分が必要です。(aflatmajb)文字列に入れる方法はありますか、それともすべてのメニューのすべてのボタンに対して手動で行う必要がありますか?