我已经使用ListView
. 我正在尝试ListView
使用ListView
. addFooterView
在此页脚中,我想添加TextView
一些文本,这些文本在我Activity
的 as a String
called中定义notification
。
我已经尝试了几件事,但它不起作用。
我的ListActivity
,RoosterWijzigingen.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 文件中获取字符串hour、info和notification的信息,但我省略了这一点以缩短代码。
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>