动作侦听器未在列表视图中工作在android系统 [英] action listener is not work in list view in android

查看:114
本文介绍了动作侦听器未在列表视图中工作在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我列出从SD卡和图像按钮,在列表视图中的视频缩略图和文本视图。
在列表视图的操作侦听器出图像按钮是工作,但我在列表中添加图像按钮查看操作监听器((敬酒不显示))不起作用。

我的XML:

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT机器人:layout_height =100dp
机器人:背景=#FFFFFF>   < ImageView的
        机器人:SRC =@绘制/图标
        机器人:ID =@ + ID /缩略图
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_centerVertical =真/><的LinearLayout机器人:方向=垂直
    机器人:layout_toRightOf =@ + ID /缩略图的an​​droid:layout_width =200dp
    机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / textLL
    机器人:layout_marginLeft =10dp>    <的TextView的android:layout_width =WRAP_CONTENT机器人:文本=FFFFF
        机器人:ID =@ + ID /文件路径机器人:layout_height =WRAP_CONTENT
        机器人:文字样式=大胆的机器人:TEXTSIZE =25dp/>    <的TextView的android:layout_width =WRAP_CONTENT
        机器人:文字=dskbdskkdsvsvsvvvfff
        机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID /标题2/>    <的LinearLayout机器人:方向=横向
        机器人:layout_gravity =CENTER_HORIZONTAL的android:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT>        < ImageButton的机器人:背景=@绘制/ play_btn
            机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
            机器人:ID =@ + ID / imageButton2机器人:layout_weight =0.5/>        < ImageButton的机器人:背景=@绘制/ details_btn
            机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
            机器人:ID =@ + ID / imageButton3机器人:layout_weight =0.5/>
    < / LinearLayout中>
< / LinearLayout中>
     < ImageButton的机器人:背景=@绘制/ buy_btn
           机器人:layout_width =WRAP_CONTENT机器人:layout_height =FILL_PARENT
           机器人:ID =@ + ID / imageButton1机器人:layout_toRightOf =@ + ID / textLL/>

如果我删除(图像按钮)以下的XML操作监听器(如图所示面包)就是工作。

 <的LinearLayout机器人:方向=横向
        机器人:layout_gravity =CENTER_HORIZONTAL的android:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT>        < ImageButton的机器人:背景=@绘制/ play_btn
            机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
            机器人:ID =@ + ID / imageButton2机器人:layout_weight =0.5/>        < ImageButton的机器人:背景=@绘制/ details_btn
            机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
            机器人:ID =@ + ID / imageButton3机器人:layout_weight =0.5/>    < / LinearLayout中>
    和
     < ImageButton的机器人:背景=@绘制/ buy_btn
           机器人:layout_width =WRAP_CONTENT机器人:layout_height =FILL_PARENT
           机器人:ID =@ + ID / imageButton1机器人:layout_toRightOf =@ + ID / textLL/>

如果我加入了XML的动作监听上述(imageButtons)不工作我不知道什么是我的XML布局的问题。请帮帮我。

我的code:

 公共类AndroidThumbnailList扩展ListActivity {
    ..........
   公共类MyThumbnaildapter扩展ArrayAdapter<串GT; {
     公共MyThumbnaildapter(上下文的背景下,INT textViewResourceId,字符串[]对象){
       超(背景下,textViewResourceId,对象);
        // TODO自动生成构造函数存根
     }
       公共查看getView(INT位置,查看convertView,父母的ViewGroup){
         .........
     }
 }保护无效onListItemClick(ListView中升,视图V,INT位置,长的id){    Log.e(视频,被称为);
    字符串选择= l.getItemAtPosition(位置)的ToString();
    Toast.makeText(getBaseContext(),选择Toast.LENGTH_SHORT).show();
}
  公共无效的onCreate(捆绑savedInstanceState){
       super.onCreate(savedInstanceState);
      _contentUri = MEDIA_EXTERNAL_CONTENT_URI;
      initVideosId();
      setListAdapter(新MyThumbnaildapter(AndroidThumbnailList.this,R.layout.row,_videosId));
  }}


解决方案

添加机器人:可聚焦=假来的ImageButton。
然后添加机器人:descendantFocusability =blocksDescendants来的ImageButton的父视图。在XML是的LinearLayout和RelativeLayout的。

in my app i list video thumb nail from sdcard and image buttons and text view in a list view. with out image buttons in the list view action listener is work but i add image buttons in the list view the action listener((toast does not show)) does not work.

my xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="100dp"
android:background="#ffffff">

   <ImageView
        android:src="@drawable/icon"
        android:id="@+id/Thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true" />

<LinearLayout android:orientation="vertical"
    android:layout_toRightOf="@+id/Thumbnail" android:layout_width="200dp"
    android:layout_height="wrap_content" android:id="@+id/textLL"
    android:layout_marginLeft="10dp">

    <TextView android:layout_width="wrap_content" android:text="fffff"
        android:id="@+id/FilePath" android:layout_height="wrap_content"
        android:textStyle="bold" android:textSize="25dp"/>

    <TextView android:layout_width="wrap_content"
        android:text="dskbdskkdsvsvsvvvfff"
        android:layout_height="wrap_content" android:id="@+id/title2" />

    <LinearLayout android:orientation="horizontal"
        android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageButton android:background="@drawable/play_btn"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:id="@+id/imageButton2" android:layout_weight="0.5" />

        <ImageButton android:background="@drawable/details_btn"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:id="@+id/imageButton3" android:layout_weight="0.5" />
    </LinearLayout>
</LinearLayout>
     <ImageButton android:background="@drawable/buy_btn"
           android:layout_width="wrap_content" android:layout_height="fill_parent"
           android:id="@+id/imageButton1" android:layout_toRightOf="@+id/textLL"/>

if i remove(image buttons) the following from xml the action listener(toast shown) is work.

        <LinearLayout android:orientation="horizontal"
        android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageButton android:background="@drawable/play_btn"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:id="@+id/imageButton2" android:layout_weight="0.5" />

        <ImageButton android:background="@drawable/details_btn"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:id="@+id/imageButton3" android:layout_weight="0.5" />

    </LinearLayout>
    and 
     <ImageButton android:background="@drawable/buy_btn"
           android:layout_width="wrap_content" android:layout_height="fill_parent"
           android:id="@+id/imageButton1" android:layout_toRightOf="@+id/textLL"/>

if i add the above(imageButtons) in the xml action listener does not work i do not know what is the problem with my xml layout. please help me.

my code:

public class AndroidThumbnailList extends ListActivity{
    ..........
   public class MyThumbnaildapter extends ArrayAdapter<String>{
     public MyThumbnaildapter(Context context, int textViewResourceId,String[] objects) {
       super(context, textViewResourceId, objects);
        // TODO Auto-generated constructor stub
     }
       public View getView(int position, View convertView, ViewGroup parent) {
         .........
     } 
 }

protected void onListItemClick(ListView l, View v, int position, long id) {

    Log.e("video", "called");
    String selection = l.getItemAtPosition(position).toString();
    Toast.makeText(getBaseContext(), selection, Toast.LENGTH_SHORT).show();
}
  public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
      _contentUri = MEDIA_EXTERNAL_CONTENT_URI;
      initVideosId();
      setListAdapter(new MyThumbnaildapter(AndroidThumbnailList.this, R.layout.row,  _videosId));
  }

}

解决方案

Add android:focusable="false" to ImageButton. Then add android:descendantFocusability="blocksDescendants" to ImageButton's parent view. In your xml is LinearLayout and RelativeLayout.

这篇关于动作侦听器未在列表视图中工作在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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