我的ListView 和系统自带的SimpleCursorAdapter里头放了一个ImageVIew,但是无法获取正确获取其点击事件应该咋整?求问
解决方案 »
- 大家好,问个关于Android 开发Webdav客户端的问题
- 急!!!安卓程序修改配置文件后不能及时更新
- Service访问
- JNI高手来帮忙出点建议
- 请问大家研究过opencore的oscl的跨平台吗?
- 把代码转换成android代码
- 为什么摄像头会出现拍照时有预览图片并可以拍照,但是录像时却没有预览图片?
- 求助,开源项目spydroid通过VLC播放器播放,为何有些手机可以播放,有一些手机却播放不了呢?
- Android 串口设备调试,debug正常调试,release 找不到方法getSupportedDevices,求大神回复
- 小白入门求救 如何获取一个手机游戏的服务器ip 求大佬
- 界面能部分加载webview吗?
- 在AndroidStudio里面搭建SQL数据库时出现如下问题
@BindView(R.id.image) ImageView image;
public ViewHolder(View view) {
ButterKnife.bind(this, view);
}
holder.image.setOnClickListener(v -> {})就可以了
MainActivity:
onCreat(){
adapter = new SimpleCursorAdapter(this, R.layout.notes_list_cell, null, new String[]{NotesDB.COLUMN_NAME_NOTE_NAME, NotesDB.COLUMN_NAME_NOTE_DATE}, new int[]{R.id.tvName, R.id.tvDate}, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
setListAdapter(adapter);
}
方法也就写了一个只有
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Cursor c = adapter.getCursor();
c.moveToPosition(position);
not_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"YOU CLICKED",Toast.LENGTH_LONG).show();
}
});
//这里的EXTRA_NOTE_ID是下一个界面里的noteId,用来判断是否需要编辑;
Intent i = new Intent(MainActivity.this, AtyEditNote.class);
i.putExtra(AtyEditNote.EXTRA_NOTE_ID, c.getInt(c.getColumnIndex(NotesDB.COLUMN_NAME_ID)));
i.putExtra(AtyEditNote.EXTRA_NOTE_NAME, c.getString(c.getColumnIndex(NotesDB.COLUMN_NAME_NOTE_NAME)));
i.putExtra(AtyEditNote.EXTRA_NOTE_CONTENT, c.getString(c.getColumnIndex(NotesDB.COLUMN_NAME_NOTE_CONTENT)));
startActivityForResult(i, REQUEST_CODE_ADD_NOTE); }两个布局文件:
activity.main
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
tools:context="example.com.notes.MainActivity"> <ImageView
android:id="@+id/bing_pic_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:alpha="150"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#00000000"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/> <ListView
android:id="@android:id/list"
android:layout_below="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutAnimation="@anim/listview_anim"
android:layout_weight="3" > </ListView>
<Button
android:alpha="100"
android:layout_marginBottom="0dp"
android:id="@+id/btnAddNote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="添加日志"/>
</LinearLayout></FrameLayout> <!-- android:layout_weight="1"
if(Build.VERSION.SDK_INT >= 21){
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
getWindow().setStatusBarColor(Color.TRANSPARENT); } <Button
android:id="@+id/btnAddNote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="添加日志"/> android:background="?attr/colorPrimary"
-->notes_list_cell.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/idtest"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvName"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="NULL TITLE"
android:textAppearance="?android:attr/textAppearanceLarge"
/> <TextView
android:id="@+id/tvDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/> </LinearLayout>
<ImageView
android:clickable="true"
android:focusable="false"
android:id="@+id/not_selected"
android:adjustViewBounds="true"
android:fitsSystemWindows="true"
android:src="@drawable/not_selected"
android:layout_width="40dp"
android:layout_height="35dp"
android:layout_marginLeft="370dp"
android:layout_centerVertical="true"
/>
</RelativeLayout>
<!-- android:layout_marginTop="15dp"-->