Selected Item of row in ListView - android

Hi I am using a Listview in my application and I created separate xml for the layout of each row of that ListView. Each row contains two ImageView and one One TextView. I want to get which ImageView is clicked on that row.

You can set OnClickListener in Adapter class itself inside getView() and get the Click Listener working for both the images. As, you haven't posted any code it not feasible to guess.

put the tag with each imageView in getView function of the adapter....
imageView.setTag(Postion);
and get in onclick with view that you received......

convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
system.out.println("position"+position)
}});

Related

Update ListView in ArrayAdapter when a row button clicked

I have a class OwnAdapter which extends the ArrayAdapter.
Data to it is passed in a arrayList.
There is a custom layout contaning 2 TextViews and 2 Buttons.
I have defined the onClick actions on the buttons in the getView method of the adapter itself.
When the button of the rows are clicked there are some changes made to the database.Now I am not getting how to update the listview when either of the 2 buttons are clicked and show the new data.
bAttend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//works fine
upDateAttend(position);
//code for updating view-What to add here?
notifyDataSetChanged();
}
});
after updating your arraylist make this line
youradapter.notifyDataSetChanged();
if you updating the arraylist in the adpater just add notifyDataSetChanged();
see this link ,talk about recyclerview but will help you
https://guides.codepath.com/android/using-the-recyclerview#notifying-the-adapter

Disable onClick on part of ListItem

I have a ListView in which each ListItem row contains some TextView and an ImageView.
When the image is clicked some XYZ operation is performed.
But I want to disable onClickListener on rest of the ListItem row.
How can this be done?
Thank You
You need to "play" with ListView settings:
// Enable elements inside listview
myListView.setItemsCanFocus(true);
//disable the focus on the whole list items
myListView.setFocusable(false);
myListView.setFocusableInTouchMode(false);
myListView.setClickable(false);
Next you need to add the attribute onClick in your imageview
<ImageView
android:id="#+id/img"
android:onClick="function"
/>
Function
public void function(View v)
{
...
}
just disable the clickable for the Listview add the android:onclick="call" attribute to the imageview
and declare call method on the corresponding activity of the Listview.
public void call(View view){
//do Something
}

List Items postion click on each row issue in android

I have a list of items in Listview.
In each row, I have Text and image. Currently, the click effect is there for the entire row. I want to add a specific click effect to text view and image.
How to do that?
I guess you have a custom adapter for your listview... so if you override the getView method, there you can set the onclick listener for each of your views.
image.setOnClickListener(new OnClickListener()
{
#Override
public void onClick()
{
// Do something
}
});
and
text.setOnClickListener(new OnClickListener()
{
#Override
public void onClick()
{
// Do something
}
});
Now, Doyou want the same listener defined in onItemClickListener in each of your views? easy: you can define your performance in another method, and only call it where you want.
I hope this help

ListView not clickable

I have an android activity that has a list view and in each list item there is a button. I want the button and the list item to be clickable but only the button is clickable and the textview on the list item is not clickable. Any idea how could this work ?. Thank you
Try the options:
If you implementet the TextView via XML-Layout use this:
<TextView
//layout and stuff
android:clickable = "true"
android:onClick = "you method name" />
if you implemented it during runtime,
use
TextView tv = new TextView.this
tv.setClickable(true);
I Thing u r Using Coustem List View in Android so u create Buttan And TextView Object in Coustem Adopter View
Add The OnClickListner In Buttan or TextView in Coustem Adopter
buttan.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0)
{
}
});
textview.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0)
{
}
});
if U want to click perticuller Buttan or TextView so Use
if(position==0)
{
click Event
}
I faced this problem before, i don't know why this is happening but i made an onclick event on the layout that holds all the list item layout instead of onitemclick event and it works for me
I found the solution for this .. add android:descendantFocusability="blocksDescendants" to the relativelayout in the xml file

Deleting an item in a list view

I am using a custom list view by extending the ArrayAdapter class. Each row has some text as well as an image. What I want to do is delete the row when I click on the imagevView. So i set an onclick listener as well as a tag for each image view and then used the onclick listener to change the adapter. However it simply refuses to work. What exactly am I doing wrong?
holder.image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view)
{
Toast.makeText(context, "ImageView clicked for the row = "+view.getTag().toString(), Toast.LENGTH_SHORT).show();
createEvent.list.remove(view.getTag());
createEvent.adapter.notifyDataSetChanged();
}
The toast prints correctly. However the item is not deleted. Any ideas on how I can achieve this?

Categories

Resources