2017-08-05 92 views
0

我有以下代码:的Android的onClick线性布局

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/list_item" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="10dp" 
    android:orientation="horizontal" 
    android:clickable="true" 
    android:onClick="openGithubUrl"> 

    <ImageView 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:src="@mipmap/github_icon"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/github_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
     <TextView 
      android:id="@+id/github_url" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 


</LinearLayout> 

我要上的LinearLayout(@ + ID /列表项)添加的onclick监听器。这可能吗?在onClick被解雇后,我想要获得孩子Textview @ + id/github_url的内容。

+0

这是在一个ListView或RecyclerView?如果是这样,你不要在linearlayout元素上设置点击监听器 –

+0

是的,它在一个ListView中 –

+0

然后你使用'listView.setOnItemClickListener',点击适配器项目,没有在LinearLayout –

回答

0

是的,您可以将onClickListener设置为线性布局,在您的用例中, listItem.setOnClickListener()在活动中。