2

我已经使用ListView. 我正在尝试ListView使用ListView. addFooterView在此页脚中,我想添加TextView一些文本,这些文本在我Activity的 as a Stringcalled中定义notification

我已经尝试了几件事,但它不起作用。

我的ListActivityRoosterWijzigingen.java

public class RoosterWijzigingen extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState); 

        ArrayList<HashMap<String, String>> roosterwijziginglist = new ArrayList<HashMap<String, String>>();         

        String hour = "4";
        String info = "Af 123";
        String notification = "Het is 40min-rooster!";

        // Creating new HashMap
        HashMap<String, String> map = new HashMap<String, String>();

        // Adding each child node to HashMap key => value
        map.put("hour", hour);
        map.put("info", info);

        // Adding HashList to ArrayList
        roosterwijziginglist.add(map);}

        ListAdapter adapter = new SimpleAdapter(this, roosterwijziginglist , R.layout.roosterwijzigingen, 
                            new String[] {"hour", "info"}, 
                            new int[] {R.id.hour, R.id.info});
        setListAdapter(adapter);

        setContentView(R.layout.listplaceholder);           
   }
}

我从 JSON 文件中获取字符串hourinfonotification的信息,但我省略了这一点以缩短代码。

listplaceholder.xml

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

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

        <TextView
                         android:id="@id/android:empty"
                         android:layout_width="fill_parent"
                         android:layout_height="wrap_content"
                         android:text="No data" />

roosterwijzigingen.xml

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

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

        <TextView  
                         android:id="@+id/info"
                         android:layout_width="match_parent" 
                         android:layout_height="fill_parent" />
</LinearLayout>
4

1 回答 1

2

在将其添加到列表之前,您必须将其放入StringaTextView中,它看起来像这样:

String footerText = "Footer text";
TextView textView = new TextView(this);
textView.setText(footerText);

getListView().addFooterView(textView);

请记住,99% 的情况下,当您想在屏幕上显示某些内容时,它必须是View

于 2013-01-03T20:38:54.243 回答