Java 从导航抽屉启动另一个listview
从当前导航抽屉listview移动到另一个listview活动时遇到问题。 从MyActivity到OS。请看公共void selection()下的案例3 MainActivity.java OperatingSystem.javaJava 从导航抽屉启动另一个listview,java,android,listview,Java,Android,Listview,从当前导航抽屉listview移动到另一个listview活动时遇到问题。 从MyActivity到OS。请看公共void selection()下的案例3 MainActivity.java OperatingSystem.java package com.example.faez.bodyalarm; 导入android.app.ListActivity; 导入android.os.Bundle; 导入android.view.view; 导入android.widget.ArrayAdap
package com.example.faez.bodyalarm;
导入android.app.ListActivity;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.ArrayAdapter;
导入android.widget.ListView;
导入android.widget.Toast;
公共类OperatingSystem扩展ListActivity{
创建公共空间(捆绑冰柱){
超级冰柱;
字符串[]值=新字符串[]{“Android”、“iPhone”、“WindowsMobile”,
“黑莓”、“WebOS”、“Ubuntu”、“Windows7”、“Max OS X”,
“Linux”、“OS/2”};
//使用自定义布局
ArrayAdapter=新的ArrayAdapter(此,
R.layout.listview、R.id.mainListView、值);
setListAdapter(适配器);
setContentView(R.layout.listview);
}
@凌驾
受保护的void onListItemClick(列表视图l、视图v、整数位置、长id){
字符串项=(字符串)getListAdapter().getItem(位置);
Toast.makeText(此项+选定项),Toast.LENGTH_LONG.show();
}
}
雄激素单
如果你们能帮忙,我真的很感激。在构建过程中没有问题,只需在电话调试时停止即可 在
案例3
中,您应该添加返回代码>后开始触觉(菜单)代码>因为在切换案例之后,如果继续,您还有一些代码将崩溃,因为“fragment”变量将保持为空。尝试检查您的OperatingSystem.java
。我认为setContentView()
在ListActivity
中不是必需的
同样对于ArrayAdapter
,您可能需要放置一个包含TextView
及其相应ID的布局
示例
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
R.layout.row_view, android.R.id.text1, values);
ArrayAdapter=新的ArrayAdapter(此,
R.layout.row_视图,android.R.id.text1,值);
行视图.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/text1" />
发生了什么?问题出现在哪里?在案例3中,fragment
保持为空,因此fragment.setArguments(args)代码>将使程序崩溃。在startActivity
之后,似乎需要return
语句。仍然无法运行该程序。有什么想法吗(还是一样的问题。我的意图正确吗?发生了什么?什么都没有?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.faez.bodyalarm" >
<application
android:debuggable="true"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name=".MainSplashScreen">
</activity>
<activity
android:name=".MyActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".OperatingSystem"></activity>
</application>
</manifest>
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
R.layout.row_view, android.R.id.text1, values);
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/text1" />