onListItemClick is not working for listview?
Add below code to your TextView
in the XML
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"
and try again.
Another simple solution: add android:descendantFocusability="blocksDescendants"
to the root viewgroup.
listview item with button not responding to onListItemClick
you can create View.OnClickListner object which can listen your imagebutton click in getView. onListItemClick generally used to handle row click event not items in rows.
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflator = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View listItem = inflator.inflate(R.layout.medcince_list_item, null);
ImageButton mEdit = (ImageButton)listItem.findViewById(R.id.item_edit);
mEdit.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// HERE YOU CAN HANDLE BUTTON CLICK. POSITION YOU CAN HAVE FROM getView already.
}
});
mEdit.setTag(getItem(position));
ImageButton mHistory = (ImageButton)listItem.findViewById(R.id.item_history);
mHistory.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// HERE YOU CAN HANDLE BUTTON CLICK. POSITION YOU CAN HAVE FROM getView already.
}
});
mHistory.setTag(getItem(position));
return listItem;
}
ListFragment OnListItemClick not being called
If you have an item in your layout that can steal input from other components like a CheckBox, that component needs to be defined as not focusable.
onListItemClick doesnt work with my ListView
It's possible to construct your ListView
by extending ListActivity
rather than Activity
- onListItemClick
will only work as it is used in you code if you extend ListActivity
. You can also unimplement OnClickListener
regardless of what you do. For instance:
public class MainActivity extends ListActivity {
String[] titles = { "One", "two", "three", "four", "five"};
String[] beschreibung = { "1", "2", "3", "4", "5"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// VivzAdapter? Good to see another SlideNerd fan :)
VivzAdapter adapter = new VivzAdapter(this, titles, beschreibung);
setListAdapter(adapter);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String cheese = titles[position];
try {
Class ourClass = Class.forName("com.example.benice." + cheese);
Intent ourIntent = new Intent(this, ourClass);
startActivity(ourIntent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
This will work for as long as you have other Classes called "One", "two", "three" etc. You also need to alter the construction of your getView()
method in the custom ArrayAdapter
.
public View getView(int position, View convertView, ViewGroup parent) {
View row;
if (convertView == null) {
LayoutInflater inflator = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflator.inflate(R.layout.row, parent, false);
} else {
row = convertView;
}
TextView titles = (TextView) row.findViewById(R.id.titleTextView);
TextView beschreibung = (TextView) row.findViewById(R.id.beschTextView);
titles.setText(titlesArray[position]);
beschreibung.setText(beschreibungArray[position]);
return row;
}
This post goes into more depth on onListItemClick
.
ListActivity's onListItemClick does not work
Try to also set the CheckBox
from the row layout as not focusable
:
//...
<CheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="4px"
android:layout_marginRight="10px"
android:focusable="false"
android:clickable="true">
//...
onListItemClick doesn't work
I found an answer to solve this by adding android:focusable="false"
inside of the the views in the listview/customlayout that will be imported to the activity. I got the answer from this link:
onListItemClick is not working for listview?
onListItemClick not working in fragment
You will need to add a OnItemClickListener
as this for ListView
:
myListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//your code over here
}
});
Hope this helps.
Android ListView - onListItemClick does not work properly
After playing around with virtually every attribute in my TextView, I finally found the reason why it was not working. It was because of the attribute android:inputType="text" in my TextView. I'm not sure why I added that piece of code (I probably copied the TextView from one of my other applications), but removing it solves my problem.
onlistitemclick in AppCompatActivity
Do this
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Note note = posts.get(position);
Intent intent = new Intent(this, EditNoteActivity.class);
intent.putExtra("noteId", note.getId());
intent.putExtra("noteTitle", note.getTitle());
intent.putExtra("noteContent", note.getContent());
startActivity(intent);
}
});
Related Topics
Enable C++11 Support on Android
Couldn't Get Connection Factory Client - Fighting with Google Maps
Android 4.3 and Phonegap, Cant Tap Link
How to Compile Ffmpeg-2.2.2 on Windows with Cygwin and Android Ndk R9C
Obtain Root Access via Su on the Android Emulator
How to Stack Firebase Cloud Messaging Notifications When the Application Is Not Running
Ionic2 Background Image Is Resized When Keyboard Is Open
Black Screen Before Splash Screen Appear in Android
Firestorepagingadapter Not Receiving Realtime Updates
Getting Error "Gradle Dsl Method Not Found: 'Compile()'" When Syncing Build.Gradle
Automatic Versioning of Android Build Using Git Describe with Gradle
How to Adjust Text Kerning in Android Textview
How to Handle Empty Response Body with Retrofit 2
How to Replace a Fragment on Button Click of That Fragment
Intent Filter to Download Attachment from Gmail Apps on Android
Timepicker Dialog from Clicking Edittext
Android Studio: Exclude Resource File Under Resources Sourcesets