Click event of listview is not working in xamarin android
up vote
2
down vote
favorite
Longclickable of listview is working like this:
Listview.LongClickable = true/false;
But Clickable is not working:
Listview.Clickable = true/false;
No syntax error. I have tried another way around like this:
Listview.IsEnabled = false;
But in this way, I have also lost LongItemClick.
What I want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time.
Please help. I am working on xamarin with visual studio 2015.
c# visual-studio xamarin.android
add a comment |
up vote
2
down vote
favorite
Longclickable of listview is working like this:
Listview.LongClickable = true/false;
But Clickable is not working:
Listview.Clickable = true/false;
No syntax error. I have tried another way around like this:
Listview.IsEnabled = false;
But in this way, I have also lost LongItemClick.
What I want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time.
Please help. I am working on xamarin with visual studio 2015.
c# visual-studio xamarin.android
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Longclickable of listview is working like this:
Listview.LongClickable = true/false;
But Clickable is not working:
Listview.Clickable = true/false;
No syntax error. I have tried another way around like this:
Listview.IsEnabled = false;
But in this way, I have also lost LongItemClick.
What I want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time.
Please help. I am working on xamarin with visual studio 2015.
c# visual-studio xamarin.android
Longclickable of listview is working like this:
Listview.LongClickable = true/false;
But Clickable is not working:
Listview.Clickable = true/false;
No syntax error. I have tried another way around like this:
Listview.IsEnabled = false;
But in this way, I have also lost LongItemClick.
What I want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time.
Please help. I am working on xamarin with visual studio 2015.
c# visual-studio xamarin.android
c# visual-studio xamarin.android
asked Nov 7 at 4:58
Sharjeel Malik
887
887
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can achieve this funtion in the way of putting a listview in an Activity, not using ListActivity. And then set the android:listSelector property of the listview to "@android:color/transparent". So the demo code is like this:
MainActivity.cs
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using System;
using Android.Views;
namespace App46
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : Activity
{
string items;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);
items = new string { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
ArrayAdapter adapter = new ArrayAdapter<String>(this, Resource.Layout.list_item, items);
ListView lv = FindViewById<ListView>(Resource.Id.listView1);
lv.Adapter = adapter;
lv.ItemLongClick += delegate (object sender, AdapterView.ItemLongClickEventArgs args)
{
Toast.MakeText(Application, ((TextView)args.View).Text, ToastLength.Short).Show();
};
}
}
}
activity_main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView1"
android:listSelector="@android:color/transparent"/>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp">
</TextView>
How is this answer to my question? You just told me to how to use listview LongItemClick. My question is different, please read again.
– Sharjeel Malik
Nov 8 at 8:10
I know what you want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time. So I tried several ways, but it didnot work. Then I found a way to make it "seems" not clickable. That is, the appearance of when you click the item is that nothing happens, no color change, no animation.
– AbbyWang
Nov 8 at 8:59
But now I think what you want is not just the appearance of not clickable, but really cannot react to click. I would work on it when I have time later.
– AbbyWang
Nov 8 at 9:27
Yes, now you have understood correctly
– Sharjeel Malik
Nov 8 at 9:33
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can achieve this funtion in the way of putting a listview in an Activity, not using ListActivity. And then set the android:listSelector property of the listview to "@android:color/transparent". So the demo code is like this:
MainActivity.cs
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using System;
using Android.Views;
namespace App46
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : Activity
{
string items;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);
items = new string { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
ArrayAdapter adapter = new ArrayAdapter<String>(this, Resource.Layout.list_item, items);
ListView lv = FindViewById<ListView>(Resource.Id.listView1);
lv.Adapter = adapter;
lv.ItemLongClick += delegate (object sender, AdapterView.ItemLongClickEventArgs args)
{
Toast.MakeText(Application, ((TextView)args.View).Text, ToastLength.Short).Show();
};
}
}
}
activity_main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView1"
android:listSelector="@android:color/transparent"/>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp">
</TextView>
How is this answer to my question? You just told me to how to use listview LongItemClick. My question is different, please read again.
– Sharjeel Malik
Nov 8 at 8:10
I know what you want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time. So I tried several ways, but it didnot work. Then I found a way to make it "seems" not clickable. That is, the appearance of when you click the item is that nothing happens, no color change, no animation.
– AbbyWang
Nov 8 at 8:59
But now I think what you want is not just the appearance of not clickable, but really cannot react to click. I would work on it when I have time later.
– AbbyWang
Nov 8 at 9:27
Yes, now you have understood correctly
– Sharjeel Malik
Nov 8 at 9:33
add a comment |
up vote
0
down vote
You can achieve this funtion in the way of putting a listview in an Activity, not using ListActivity. And then set the android:listSelector property of the listview to "@android:color/transparent". So the demo code is like this:
MainActivity.cs
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using System;
using Android.Views;
namespace App46
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : Activity
{
string items;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);
items = new string { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
ArrayAdapter adapter = new ArrayAdapter<String>(this, Resource.Layout.list_item, items);
ListView lv = FindViewById<ListView>(Resource.Id.listView1);
lv.Adapter = adapter;
lv.ItemLongClick += delegate (object sender, AdapterView.ItemLongClickEventArgs args)
{
Toast.MakeText(Application, ((TextView)args.View).Text, ToastLength.Short).Show();
};
}
}
}
activity_main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView1"
android:listSelector="@android:color/transparent"/>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp">
</TextView>
How is this answer to my question? You just told me to how to use listview LongItemClick. My question is different, please read again.
– Sharjeel Malik
Nov 8 at 8:10
I know what you want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time. So I tried several ways, but it didnot work. Then I found a way to make it "seems" not clickable. That is, the appearance of when you click the item is that nothing happens, no color change, no animation.
– AbbyWang
Nov 8 at 8:59
But now I think what you want is not just the appearance of not clickable, but really cannot react to click. I would work on it when I have time later.
– AbbyWang
Nov 8 at 9:27
Yes, now you have understood correctly
– Sharjeel Malik
Nov 8 at 9:33
add a comment |
up vote
0
down vote
up vote
0
down vote
You can achieve this funtion in the way of putting a listview in an Activity, not using ListActivity. And then set the android:listSelector property of the listview to "@android:color/transparent". So the demo code is like this:
MainActivity.cs
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using System;
using Android.Views;
namespace App46
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : Activity
{
string items;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);
items = new string { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
ArrayAdapter adapter = new ArrayAdapter<String>(this, Resource.Layout.list_item, items);
ListView lv = FindViewById<ListView>(Resource.Id.listView1);
lv.Adapter = adapter;
lv.ItemLongClick += delegate (object sender, AdapterView.ItemLongClickEventArgs args)
{
Toast.MakeText(Application, ((TextView)args.View).Text, ToastLength.Short).Show();
};
}
}
}
activity_main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView1"
android:listSelector="@android:color/transparent"/>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp">
</TextView>
You can achieve this funtion in the way of putting a listview in an Activity, not using ListActivity. And then set the android:listSelector property of the listview to "@android:color/transparent". So the demo code is like this:
MainActivity.cs
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using System;
using Android.Views;
namespace App46
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : Activity
{
string items;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_main);
items = new string { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
ArrayAdapter adapter = new ArrayAdapter<String>(this, Resource.Layout.list_item, items);
ListView lv = FindViewById<ListView>(Resource.Id.listView1);
lv.Adapter = adapter;
lv.ItemLongClick += delegate (object sender, AdapterView.ItemLongClickEventArgs args)
{
Toast.MakeText(Application, ((TextView)args.View).Text, ToastLength.Short).Show();
};
}
}
}
activity_main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView1"
android:listSelector="@android:color/transparent"/>
</LinearLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp">
</TextView>
answered Nov 8 at 6:45
AbbyWang
1064
1064
How is this answer to my question? You just told me to how to use listview LongItemClick. My question is different, please read again.
– Sharjeel Malik
Nov 8 at 8:10
I know what you want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time. So I tried several ways, but it didnot work. Then I found a way to make it "seems" not clickable. That is, the appearance of when you click the item is that nothing happens, no color change, no animation.
– AbbyWang
Nov 8 at 8:59
But now I think what you want is not just the appearance of not clickable, but really cannot react to click. I would work on it when I have time later.
– AbbyWang
Nov 8 at 9:27
Yes, now you have understood correctly
– Sharjeel Malik
Nov 8 at 9:33
add a comment |
How is this answer to my question? You just told me to how to use listview LongItemClick. My question is different, please read again.
– Sharjeel Malik
Nov 8 at 8:10
I know what you want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time. So I tried several ways, but it didnot work. Then I found a way to make it "seems" not clickable. That is, the appearance of when you click the item is that nothing happens, no color change, no animation.
– AbbyWang
Nov 8 at 8:59
But now I think what you want is not just the appearance of not clickable, but really cannot react to click. I would work on it when I have time later.
– AbbyWang
Nov 8 at 9:27
Yes, now you have understood correctly
– Sharjeel Malik
Nov 8 at 9:33
How is this answer to my question? You just told me to how to use listview LongItemClick. My question is different, please read again.
– Sharjeel Malik
Nov 8 at 8:10
How is this answer to my question? You just told me to how to use listview LongItemClick. My question is different, please read again.
– Sharjeel Malik
Nov 8 at 8:10
I know what you want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time. So I tried several ways, but it didnot work. Then I found a way to make it "seems" not clickable. That is, the appearance of when you click the item is that nothing happens, no color change, no animation.
– AbbyWang
Nov 8 at 8:59
I know what you want is that "ItemClick not clickable" and "LongItemClickable clickable" at same time. So I tried several ways, but it didnot work. Then I found a way to make it "seems" not clickable. That is, the appearance of when you click the item is that nothing happens, no color change, no animation.
– AbbyWang
Nov 8 at 8:59
But now I think what you want is not just the appearance of not clickable, but really cannot react to click. I would work on it when I have time later.
– AbbyWang
Nov 8 at 9:27
But now I think what you want is not just the appearance of not clickable, but really cannot react to click. I would work on it when I have time later.
– AbbyWang
Nov 8 at 9:27
Yes, now you have understood correctly
– Sharjeel Malik
Nov 8 at 9:33
Yes, now you have understood correctly
– Sharjeel Malik
Nov 8 at 9:33
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53183783%2fclick-event-of-listview-is-not-working-in-xamarin-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown