android


ListView OnItemClickListener doesn't fire


I'm at a loss.
I have a ListView being set via adapter in a fragment.
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_knowledgebase, container, false);
// Set the adapter
mListView = (AbsListView) view.findViewById(R.id.searchResultList);
// Set OnItemClickListener so we can be notified on item clicks
mListView.setOnItemClickListener(this);
mListView.setAdapter(mAdapter);
return view;
}
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (null != mCallback) {
//call back to activity
mCallback.onFragmentInteraction(position);
}
}
The layout of the list is dead simple. Only 1 text view, no buttons or check boxes.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/searchResultList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:footerDividersEnabled="true"
android:clickable="true"
/>
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="start"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
android:textIsSelectable="false"/>
I've set focusable properties to false and still no dice
The main problem is your variable mCallback is null. So the code below this is not triggering...
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (null != mCallback) {
//call back to activity
mCallback.onFragmentInteraction(position);
}
}
this is almost this
if (null != null) {
to check my answer, try this:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.e("ListView OnItemClick","Clicked");
if (null != mCallback) {
//call back to activity
mCallback.onFragmentInteraction(position);
}
}
This will log ListView OnItemClick Clicked
Maybe it should be onListItemClick
#Override
public void onListItemClick(ListView l, View v, int position, long id) {

Related Links

Provide AsyncTask with arguments unknown to the UI?
RSS Feed image downloading
QCom Decoder Output YUV Buffer Distrubed
Unable to scroll LinearLayout which is placed in ScrollView
Unable to click entire row in custom Listview
How to add footer to the layout?
Get location of android widget
Suppress successful lint output in Gradle
while executing android code it sowing Exception in thread “main” java.lang.ExceptionInInitializerError
Change language of offline speech recognition
NullPointerException when run with Intellij IDEA new libgdx project for android
Deploying an iOS App using PhoneGap From Windows
Android 4.4+ How do apps like MightyText and AirDroid send SMS?
What is the sampling frequency of the accelerometers embedded in Android smartphone?
UiAutomator Android - setText method is not working.!
Using Proguard With Android Studio problems generating signed apk

Categories

HOME
uml
url-redirection
c99
apache-flink
dns
android-studio-2.2
nunit
interface
serialization
switch-statement
permissions
hugo
regular-language
mapbox
qpython
jxl
gruntfile
google-data-studio
nim
undertow
rubymotion
blade
tiki-wiki
siri
ntp
boost-asio
dst
kudu
fstream
installscript
modalviewcontroller
imx6
sim-toolkit
node-mssql
css-position
demo
hackintosh
setup.py
subclipse
ssrs-2014
placeholder
knime
dynamic-linq
jboss-4.2.x
hammer.js
launchctl
identification
activeperl
java-bytecode-asm
materialized-path-pattern
taocp
pacemaker
burrows-wheeler-transform
xdoclet
deep
phpwebsocket
np-spring
user-management
state-restoration
character-replacement
grgit
microsoft-reporting
ess
android-launcher
airbrake
keyup
aspectj-maven-plugin
snackbar
actionfilterattribute
theos
android-vibration
browserify-shim
ignite-ui
amslidemenu
spring-3
scrypt
alice
idn
frameworkelementfactory
pinch
screen-size
listactivity
google-ajax-api
mbeans
http-daemon
msr
django-paypal
nhprof
ie-compatibility-mode
dojo-dnd
escrow
idatareader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App