AdapterView.OnItemClickListener()在我的customAdapter中不起作用 [英] AdapterView.OnItemClickListener() is not working in my customAdapter

查看:82
本文介绍了AdapterView.OnItemClickListener()在我的customAdapter中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参考这张图片 https://www.dropbox.com/s/6zoj9lw10oc07xa/to_dropbox.png

what i am doing : 我正在创建一个list_view,其中要添加自定义适配器.

what i am doing : i am creating a list_view , in which i am adding custom adapter .

what i am using : 我正在使用listView,customAdapter,menuitem. listView:整个应用程序中的单个列表视图 customadapters:3个自定义适配器 menuitem:1

what i am using : i am using , listView , customAdapter , menuitem . listView : single listview in whole application customadapters : 3 custom adapters menuitem : 1

How i am implementing : 我有一个可以从中正确提取数据的数据库,并且通过从3种类型的数据中筛选出这些数据,从该数据库中我在列表视图中输入了这些值: 默认情况下(在onCreate中)输入第一个adapter_type.

How i am implementing : i have data base from which things are fetched properly , and from that database i have entered these values in my listview by filtering that data in 3 types : 1st adapter_type is entered by default ( in onCreate ) .

adapter = new Adapter_forCompletedReminder( array_today_title , this) ;
ls.setAdapter(adapter) ;

按下menuitem在我的列表视图中输入

第二个adapter_type.

2nd adapter_type is entered in my listview by pressing menuitem .

adapter = new Adapter_forCompletedReminder( array_past_2_day_title , this) ;
ls.setAdapter(adapter) ;

通过按menuitem在我的列表视图中输入

第3个adapter_type.

3rd adapter_type is entered in my listview by pressing menuitem .

adapter = new Adapter_forCompletedReminder( array_other_day_title , this) ;
ls.setAdapter(adapter) ;

what is my problem : 这段代码被添加到onCreate()方法中.

what is my problem : this code is added inside onCreate() method .

ls.setOnItemClickListener( new AdapterView.OnItemClickListener() 
{
    public void onItemClick(AdapterView<?> adapterView , View view , int position ,long arg3) 
    {
        Log.i("Item clicked","tushar:itemclicked") ;
    }
});

当我尝试实现AdapterView.OnItemClickListener()时,它不起作用... 代码没有崩溃(log cat中没有红线). 单击llist_view_element不会执行代码

when i have tried to implement AdapterView.OnItemClickListener() , it is not working ... code is not crashing ( no red lines in log cat ). code is not executing in the click of llist_view_element

感谢您阅读我的问题.

推荐答案

您在customview_completedxml_listview.xml中使用了复选框,这就是onItemClick侦听器不起作用的原因.如果您在复选框中设置clickable ="false",则onItemclick侦听器将起作用.

You use checkbox in customview_completedxml_listview.xml that is why onItemClick listener is not working. If you set clickable = "false" in checkbox then onItemclick listener will work.

如果您希望该复选框仍然有效,则必须在自定义适配器类中设置onclicklistener事件.

If you want want that checkbox will stil work then you have to set onclicklistener event in you custom adapter class.

//我编辑getView

// I edit getView

 @Override
  public View getView(int position, View convertView, ViewGroup parent)  
   { 
    LayoutInflater inflater = LayoutInflater.from(ob) ; 
    View v = inflater.inflate(R.layout.customview_completedxml_listview, null ) ; 


     TextView txt = ( TextView ) v.findViewById(R.id.txt_fordisplayingdata) ; 
      txt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
             Toast.makeText(ob, "Hello", Toast.LENGTH_SHORT).show();

        }
    });
      txt.setText(recieved_Array[position]) ; 

      return v ; 
   } 

///////////////////////// //第二个解决方案在复选框中设置了android:focusable ="false"

/////////////////////// // Second solution set android:focusable="false" in checkbox

     <?xml version="1.0" encoding="utf-8"?> 
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="50dp"
       android:orientation="horizontal" 
       > 

    <TextView 
    android:id="@+id/txt_fordisplayingdata"
    android:layout_width="240dp"
    android:text="display data"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginLeft="10dp"
    /> 

  <TextView 
    android:id="@+id/txt_fordisplayingLargerdata"
    android:layout_width="240dp"
    android:text="display data larger bahut larger "
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginLeft="10dp"
    android:visibility="gone"
    /> 

  <View
    android:layout_width="2dp"
    android:layout_toRightOf="@id/txt_fordisplayingdata"
    android:layout_height="15dp"
    android:layout_marginLeft="15dp"
    android:layout_centerVertical="true"
    android:id="@+id/view_forcompletedtask"
    /> 


  <CheckBox 
    android:layout_toRightOf="@id/view_forcompletedtask"
    android:id="@+id/checkbox_tocomplete"
    android:layout_marginLeft="15dp"
    android:layout_width="wrap_content"
    android:focusable="false"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    /> 

</RelativeLayout>

这篇关于AdapterView.OnItemClickListener()在我的customAdapter中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆