とActivity
呼ばれるファイルMainActivity.java
があります。activity_main.xml
しかし、 という別のアクティビティを起動するリンクを作成する方法がわかりませんDirectionActivity
。以下は私のコードのサンプルです。
文字列.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">EEMA</string>
<string name="action_settings">Settings</string>
<string name="hello_world">The Emergency Evacuation Mobile App!</string>
<string name="directions">\n\nTo view directions click here!</string>
<string name="title_activity_direction">DirectionActivity</string>
<string name="title_activity_main">MainActivity</string>
</resources>
activity_main.xml テキストビュー
<TextView android:id="@+id/txtView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp"
android:textColorLink="#FFFF00"
android:textStyle="bold"
/>
MainActivity.java
public class MainMenuActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
String str = "Please click here to view Directions";
TextView txtView = (TextView) findViewById(R.id.txtView);
txtView.setText(str);
Linkify.addLinks(txtView, Linkify.ALL);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
}
方向アクティビティ.java
public class DirectionActivity extends Activity {
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String message = intent.getStringExtra(MainMenuActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
setContentView(R.layout.activity_direction);
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
}
では、DirectionActivity を開くリンクとして表示される [ここをクリックしてルートを表示] を取得するには、どうすればよいでしょうか?