*MainActivity de button'a yaptırdığım işlemde SecondActivity class'ına geçebildiğim halde, option menude bu işlemi yapamıyorum.
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_main);
buradan = (TextView) findViewById(R.id.textBuradan);
buraya = (TextView) findViewById(R.id.textBuraya);
final Bundle bundle = new Bundle();
intent = newIntent(MainActivity.this,SecondActivity.class);
Button btn=(Button)(findViewById(R.id.btn_go));
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String bu1 = buradan.getText().toString();
String bu2 = buraya.getText().toString();
bundle.putString("bnd1", bu1);
bundle.putString("bnd2", bu2);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.optionsmenu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()){
case R.id.menu1:
Toast.makeText(getApplicationContext(), "Ana Menü", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu2:
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
-----------------------------------------------------------------------------------------
*Bu bölümde hem buton ile hem de option menu ile MainActivity class'ına dönebiliyorum. Bir sorun yok.
public class SecondActivity extends Activity {
Intent intent;
protected void onCreate(Bundle arg0){
super.onCreate(arg0);
setContentView(R.layout.second_activity);
TextView t1 = (TextView)findViewById(R.id.textburadan2);
TextView t2 = (TextView)findViewById(R.id.textburaya2);
intent = new Intent(SecondActivity.this,MainActivity.class);
Bundle bb = getIntent().getExtras();
String ss = bb.getString("bnd1");
String ss2 = bb.getString("bnd2");
t1.setText("burdan: " + ss);
t2.setText("buraya: " + ss2);
Button btn =(Button)(findViewById(R.id.btn_back));
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.optionsmenu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()){
case R.id.menu1:
startActivity(intent);
return true;
case R.id.menu2:
Toast.makeText(getApplicationContext(), "Yan Menü", Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item);
}
}
**Umarım örnek kod sorunu anlamak için yeterli olur