在我的片段中,我有一个列表视图,单击时将打开另一个与列表中项目相对应的活动。但是实际上不起作用,单击时什么也没有发生。
@SuppressLint("NewApi")
protected void onListItemClick(ListView l, View v, int positionItem, long id) {
Sensor sensor = sensorAdapter.getItem( positionItem ).getSensor();
String sensorName = sensor.getName();
Intent i = new Intent(getActivity(), SensorMonitor.class);
startActivity(i);
i.putExtra( "sensorname",sensorName );
startActivity( i );
}
有什么帮助吗?如果您想问我,logCat什么也没说。.我可以单击,但什么也没有发生。.我还添加了listview的textview:
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"
但是什么都没有
编辑:
这是列表视图的自定义文本视图:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:fontFamily="sans-serif-light"
android:gravity="center_vertical"
android:padding="10dp" />
这是片段xml,其中有listview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Included header.xml here -->
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<TextView
android:id="@+id/titolodevicefragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#DB3232"
android:textSize="18dp"
android:fontFamily="sans-serif-condensed"
android:text="@string/titolosensorsfragment" />
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableLayout>
</LinearLayout>
尝试实现listview.setonItemClickListener。它应该可以正常工作,否则似乎没有问题
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句