2011-06-09 27 views
0

列表视图列表视图列表视图缩略图从SD卡和图像按钮和文本视图列表视图中。 与列表视图中的图像按钮动作侦听器工作,但我添加图像按钮在列表视图动作侦听器((吐司不显示))不起作用。动作监听器不能在我的应用程序中的Android

我的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"/> 

如果删除(图像按钮)从XML以下的动作侦听器(示出烤面包)是工作。

 <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"/> 

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

我的代码:

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)); 
    } 

} 

回答

1

添加机器人:可调焦= “false” 表示的ImageButton。 然后将android:descendantFocusability =“blocksDescendants”添加到ImageButton的父视图。在你的xml中是LinearLayout和RelativeLayout。

+0

谢谢你的代码是作品(吐司显示)。如何为每个图像按钮编写单独的动作保护无效onListItemClick(ListView l,View v,int position,long id){ ............ }请帮助我。 – 2011-06-09 05:16:17

相关问题