我有一个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 的链接?