Android 无法在listview中设置McClickListener
我的布局代码如下所示:Android 无法在listview中设置McClickListener,android,Android,我的布局代码如下所示: <?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_hei
<?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();
}
});`
list_notification.setVisibility(视图.VISIBLE);
字符串s[]=新字符串[]{“您的请假请求已被接受”,
“测试通知”};
ArrayAdapter adpt=新的ArrayAdapter(此,
android.R.layout.simple_list_item_1,s);
列表\u通知setAdapter(adpt);
list_notification.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
公共链接(AdapterView arg0、视图arg1、,
整数arg2,长arg3){
Toast.makeText(getApplicationContext(),
“单击列表项”,Toast.LENGTH_SHORT.show();
}
});`
我认为
中的这一行可能是罪魁祸首:
android:focusable="false"
假设您的错误仅仅是单击项目没有任何作用
您的UI可能存在其他问题…当列表高于屏幕时,将列表视图堆叠在滚动视图的顶部会产生问题。我认为
中的这一行可能是罪魁祸首:
android:focusable="false"
假设您的错误仅仅是单击项目没有任何作用
您的UI可能还有一些其他问题……当列表高于屏幕时,将列表视图堆叠在滚动视图的顶部会产生问题。问题在于布局,请在下方添加android:layout\u=“@id/list\u notification”
ScrollView不会覆盖listview
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/list_notification"
>
问题在于布局,在下面添加android:layout\u=“@id/list\u notification”
ScrollView不会覆盖listview
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/list_notification"
>
您能将错误发布到它抛出的日志中吗?或者这是IDE的错误?我的logcat没有显示任何与listview相关的错误。这是您的代码编译吗?还是与语法错误有关?导入是否正确?应使用以下导入:import android.widget.AdapterView;导入android.widget.AdapterView.OnItemClickListener;导入android.widget.ArrayAdapter
并尝试在ArrayAdapter中使用类参数,类似这样的ArrayAdapter mAdapter=newArrayAdapter(…)代码>其中T是一个对象,其onString方法被覆盖!如果Logcat没有显示任何与listview或其侦听器相关的错误,那么会发生什么?因为您已经正确地实现了这个简单的侦听器。难道它只是不显示祝酒词还是什么?试着告诉更多你能把它抛出的错误贴出来吗?或者这是IDE的错误?我的logcat没有显示任何与listview相关的错误。这是您的代码编译吗?还是与语法错误有关?导入是否正确?应使用以下导入:import android.widget.AdapterView;导入android.widget.AdapterView.OnItemClickListener;导入android.widget.ArrayAdapter
并尝试在ArrayAdapter中使用类参数,类似这样的ArrayAdapter mAdapter=newArrayAdapter(…)代码>其中T是一个对象,其onString方法被覆盖!如果Logcat没有显示任何与listview或其侦听器相关的错误,那么会发生什么?因为您已经正确地实现了这个简单的侦听器。难道它只是不显示祝酒词还是什么?多说点