我的布局代码如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relRingtone"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:focusable="false"
android:id="@+id/list_notification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:layout_marginLeft="3dip"
android:textSize="2dp" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="40dp" >
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:background="@drawable/button"
android:padding="5dp"
android:text="Start Working"
android:textColor="#FFF"
android:textSize="20sp"
android:textStyle="bold" />
<Chronometer
android:id="@+id/chronometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn1"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:padding="5dp"
android:text="Vehicle Details"
android:textColor="#FFF"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="gone" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/chronometer"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:background="@drawable/button"
android:padding="5dp"
android:text="Take Leave"
android:textColor="#FFF"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
下面是我的java代码:
list_notification.setVisibility(View.VISIBLE);
String s[] = new String[] { "Your leave request has been accepted",
"test notification" };
ArrayAdapter<String> adpt = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, s);
list_notification.setAdapter(adpt);
list_notification.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Toast.makeText(getApplicationContext(),
"list item clicked", Toast.LENGTH_SHORT).show();
}
});`