我在 xml、android 中创建了一个列表。它的 java 代码具有扩展 Activity 而不是扩展列表活动。当我单击特定行时,我无法编写代码来启动新活动。这是我的代码...
JAVA代码
import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends Activity {
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
ArrayAdapter adapter = new ArrayAdapter<String>(this,``
android.R.layout.simple_list_item_1, values);
ListView View = (ListView) findViewById(R.id.list);
View.setAdapter(adapter);
}
XML 代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="4dp"
android:background="@drawable/ic_launcher">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="200dp"
android:layout_height="325dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="false" >
</ListView>
</RelativeLayout>