android:Tab下的listActivity
抱歉,如果这是重复的,我在网上找到的解决方案都不适合我。
我有 2 个选项卡,我正在尝试将列表添加到其中一个选项卡。代码如下:
public class Library extends ListActivity {
ParsingDBHelper mDbHelper;
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extra = getIntent().getExtras();
String temp = extra.getString(Httpdwld.RESULT);
mDbHelper = new ParsingDBHelper(this);
mDbHelper.open();
parsing();
fillData();
}
private void parsing() {
// IMPLEMENT
}
private void fillData() {
Cursor c = mDbHelper.fetchAllSearch();
String[] FROM = new String[] {ParsingDBHelper.KEY_TITLE, ParsingDBHelper.KEY_AUTHOR,
ParsingDBHelper.KEY_YEAR, ParsingDBHelper.KEY_LOCATION,
ParsingDBHelper.KEY_CALL_ISBN, ParsingDBHelper.KEY_AVAILABILITY};
int[] TO = new int[] {R.id.row_title, R.id.row_author, R.id.row_year,
R.id.row_location, R.id.row_id, R.id.row_avail};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.row_layout, c, FROM, TO);
lv.setAdapter(notes);
}
}
mDbHelper 只是一个使用 SQLiteDatabase 的助手。
这是我的选项卡 XML 代码
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp" >
</FrameLayout>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>>
</TabHost>
,但我不断收到“无法启动活动:库”错误。这是我调用图书馆的地方
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_result);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent(this, Library.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Library").setIndicator("Library")
.setContent(intent);
tabHost.addTab(spec);
}
有什么建议吗?
Sorry if this is a repeat, none of the solutions I found online worked for me.
I have 2 tabs, and I'm trying to add a list unto one of the tabs. Here's the code:
public class Library extends ListActivity {
ParsingDBHelper mDbHelper;
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extra = getIntent().getExtras();
String temp = extra.getString(Httpdwld.RESULT);
mDbHelper = new ParsingDBHelper(this);
mDbHelper.open();
parsing();
fillData();
}
private void parsing() {
// IMPLEMENT
}
private void fillData() {
Cursor c = mDbHelper.fetchAllSearch();
String[] FROM = new String[] {ParsingDBHelper.KEY_TITLE, ParsingDBHelper.KEY_AUTHOR,
ParsingDBHelper.KEY_YEAR, ParsingDBHelper.KEY_LOCATION,
ParsingDBHelper.KEY_CALL_ISBN, ParsingDBHelper.KEY_AVAILABILITY};
int[] TO = new int[] {R.id.row_title, R.id.row_author, R.id.row_year,
R.id.row_location, R.id.row_id, R.id.row_avail};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.row_layout, c, FROM, TO);
lv.setAdapter(notes);
}
}
mDbHelper is simply a a helper for using SQLiteDatabase.
Here's my XML code for the Tabs
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp" >
</FrameLayout>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>>
</TabHost>
But I keep getting "Cannot start Activity: Library" error. Here's where I call Library
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_result);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent(this, Library.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Library").setIndicator("Library")
.setContent(intent);
tabHost.addTab(spec);
}
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的活动必须在 AndroidManifest.xml 中列出。您的 logcat 也会将其显示为异常。
Your activity must by listed in your AndroidManifest.xml. Your logcat would also show that as an exception.