Home > Mobile >  Want to set the ImageView click event
Want to set the ImageView click event

Time:10-02

The SimpleCursorAdapter system at my ListView and inside put a ImageVIew, but unable to get access to the click event should be right? Inquire of

CodePudding user response:

Directly to set an OnCLickListener ImageView, what's the problem?

CodePudding user response:

In the adapter, give imageView set the listener

CodePudding user response:

Adapter bound
@ BindView (R.i d.i mage) ImageView image;
Public ViewHolder View (View) {
ButterKnife. Bind (this view);
}


Holder. The image. SetOnClickListener (v - & gt; {})

CodePudding user response:

What is unable to get click event, listview. SetOnItemClick... No mean? Send a code

CodePudding user response:

The code is probably like this:
MainActivity:
OnCreat () {
Adapter=new SimpleCursorAdapter (this, R.l ayout. Notes_list_cell, null, new String [] {NotesDB. COLUMN_NAME_NOTE_NAME, NotesDB COLUMN_NAME_NOTE_DATE}, new int [] {R.i which vName, R.i which vDate}, CursorAdapter. FLAG_REGISTER_CONTENT_OBSERVER);
SetListAdapter (adapter);
}


Method would be to write a only
Protected void onListItemClick (ListView l, View v, int position, long id) {
Super. OnListItemClick (l, v, position, id);
Cursor c=adapter. GetCursor ();
C. oveToPosition (position);
Not_delete. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
YOU Toast. MakeText (MainActivity. This, "CLICKED", Toast. LENGTH_LONG). The show ();
}
});
//the EXTRA_NOTE_ID here is the next noteId in the interface, is used to determine whether you need to edit;
Intent I=new Intent (MainActivity. This, AtyEditNote. Class);
Be sad etInt chtistina georgina rossetti.british poetess i.p utExtra (AtyEditNote EXTRA_NOTE_ID, be sad etColumnIndex chtistina georgina rossetti.british poetess ((NotesDB. COLUMN_NAME_ID)));
Be sad etString chtistina georgina rossetti.british poetess i.p utExtra (AtyEditNote EXTRA_NOTE_NAME, be sad etColumnIndex chtistina georgina rossetti.british poetess ((NotesDB. COLUMN_NAME_NOTE_NAME)));
Be sad etString chtistina georgina rossetti.british poetess i.p utExtra (AtyEditNote EXTRA_NOTE_CONTENT, be sad etColumnIndex chtistina georgina rossetti.british poetess ((NotesDB. COLUMN_NAME_NOTE_CONTENT)));
, REQUEST_CODE_ADD_NOTE startActivityForResult (I);

}



Two layout file:
Activity. The main
<? The XML version="1.0" encoding="utf-8"?>
<frameLayout XMLNS: android="http://schemas.android.com/apk/res/android"
XMLNS: tools="http://schemas.android.com/tools"
The 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" & gt;

The android: id="@ + id/bing_pic_img"
Android: layout_width="match_parent"
Android: layout_height="match_parent"
Android: scaleType="centerCrop"
Android: alpha="150"
/& gt;
Android: orientation="vertical"
Android: layout_width="match_parent"
Android: layout_height="match_parent" & gt;
The 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"
/& gt;

The 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"


Android: alpha="100"
Android: layout_marginBottom="0 dp"
The android: id="@ + id/btnAddNote"
Android: layout_width="match_parent"
Android: layout_height="wrap_content"
Android: text="add"/& gt;






If (Build) VERSION) SDK_INT & gt; {
=21)The View decorView=getWindow (). GetDecorView ();
DecorView. SetSystemUiVisibility (the SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | the SYSTEM_UI_FLAG_LAYOUT_STABLE);
GetWindow (). SetStatusBarColor (Color. TRANSPARENT);

}

The android: id="@ + id/btnAddNote"
Android: layout_width="match_parent"
Android: layout_height="wrap_content"
Android: text="add"/& gt;

Android: background="? Attr/colorPrimary
"-->



XML notes_list_cell.
<? The XML version="1.0" encoding="utf-8"?>
XMLNS: android="http://schemas.android.com/apk/res/android"
The android: orientation="horizontal"
Android: layout_width="match_parent"
Android: layout_height="match_parent" & gt;

XMLNS: android="http://schemas.android.com/apk/res/android"
The android: id="@ + id/idtest"
Android: orientation="vertical"
Android: layout_width="match_parent"
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related