问题描述
我有这个类的一个问题。该活动将被调用时,我preSS的按钮。当我向活动这一类PROGRAMM进入类,但是当我向ListActiviy,我按一下按钮,调试器告诉我红色的字源未找到没有别的,甚至没有东西在logcat中。请告诉我,如果有东西在这个活动或清单的XML文件丢失。
I've got a problem with this class. This Activity will be called when I press a button. When I extend Activity to this class the programm gets into the class, but when I extend ListActiviy and I click the button the debugger tells me in red words "source not found" and nothing else, not even something in the logcat.Please tell me if there is something missing in the xml-file of this activity or the manifest.
这是类活动:
public class SeeAllEntriesActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_entries);
ActivitiesObjects ao = (ActivitiesObjects)this.getApplication();
List<Customer> listOfCostumer = ao.getListOfCustomers();
ListAdapter listAdapter = new ArrayAdapter(this, R.layout.activity_all_entries, listOfCostumer);
ListView listViewCustomer = (ListView) findViewById(R.id.listViewCustomer);
listViewCustomer.setAdapter(listAdapter);
}
}
这是该活动的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="all entries" />
<ListView
android:id="@+id/listViewCustomer"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
这是清单的XML:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application android:name="com.example.testapp.ActivitiesObjects" android:label="@string/app_name">
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="CreateActivity"></activity>
<activity android:name="SeeAllEntriesActivity"></activity>
</application>
</manifest>
在此先感谢,亚历克斯
Thanks in advance,alex
推荐答案
有一点我想分享关于ListActivity。
One point I like to share regarding ListActivity.
您的布局中必须包含了Android一个ListView:id属性设置 到@android:ID /列表
例如机器人:ID =@机器人:ID /列表
For example android:id="@android:id/list"
有你的布局文件会像下面
there for your layout file will be like below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="all entries" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
有关设置列表适配器,你可以使用 setListAdapter
功能
For setting list adapter you can use setListAdapter
function
public class SeeAllEntriesActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_entries);
ActivitiesObjects ao = (ActivitiesObjects)this.getApplication();
List<Customer> listOfCostumer = ao.getListOfCustomers();
ListAdapter listAdapter = new ArrayAdapter(this, R.layout.activity_all_entries, listOfCostumer);
// no need to fetch list view instance
// ListView listViewCustomer = (ListView) findViewById(R.id.listViewCustomer);
setListAdapter(listAdapter);
}
}
如果你想拥有列表视图的实例,那么你可以调用 getListView()
If you want to have instance of listview then you can call getListView ()
这篇关于为什么我得到&QUOT;源未发现与QUOT;当我改变延伸活动,以扩展ListActivity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!