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.










share|improve this question


























    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.










    share|improve this question
























      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 4:58









      Sharjeel Malik

      887




      887
























          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>





          share|improve this answer





















          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          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>





          share|improve this answer





















          • 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















          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>





          share|improve this answer





















          • 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













          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>





          share|improve this answer












          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>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()