2011-05-27 62 views
1

我不知道发生了什么我第一次发布这个扩展活动的类。但即使将其更改为ListActivity,它仍然不起作用。我会把它贬低到我认为问题所在的地方。问题与我的setListAdapter()

public class PassScreen extends ListActivity { 
String[] items = {"lorem","ipsum", "dolor"};// I have it calling an xml file but switched it to this just to see if that was the problem. 
setContentView(R.layout.passwordscreen); 
setListAdapter(new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1, 
      items)); 

我不明白你的意思。这是我的书使用的。我检查,以确保xml文件显示适当的ListView和它。但在这里它是无论如何:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<TextView 
android:id="@+id/selection" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"/> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:drawSelectorOnTop="false"/> 

</LinearLayout> 
+0

你有什么错误? – 2011-05-27 06:46:03

+0

不,我可以运行该应用程序。 – Funlamb 2011-05-27 06:50:12

+0

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List1.html – 2011-05-27 06:59:56

回答

1

行,所以我只是发现了这个问题。哎呀!这就是我喜欢编程的原因。我的布局需要一个方向。

所以:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

应该是这个样子的:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" // This is the difference. 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
1

试试这个..

getListView().setListAdapter(new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, items)); 
     getListView().setTextFilterEnabled(true); 
+0

工作。我只是不知道如何使用没有XML文件的任何东西。 – Funlamb 2011-05-27 06:52:22

+0

“android.R.layout.simple_list_item_1”这行代表LISTVIEW ..而你有listactivity然后listview自动生成这个代码 – 2011-05-27 06:55:34

+0

我不完全理解。假设我想将文本视图更改为选定内容。喜欢这个。我该怎么去做呢? public void onListItemClick(ListView parent,View v,int position,long id){ // \t selection.setText(items.get(position).toString()); \t selection.setText(items [position]); – Funlamb 2011-05-27 06:58:05