I know this is a question that has been asked before, but I think I’m doing the correct coding, and yet, I’m not coming up with the proper result. Here my xml code:
<LinearLayout
android:id="@+id/directions_layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:clickable="true">
<ImageView android:src="@drawable/icon_directions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"/>
<TextView android:text="Directions"
android:textColor="@color/gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"/>
</LinearLayout>
I don’t know if this makes a difference or not, but the LinearLayout that is the parent of the one shown is not clickable.
Here is where I set the OnClickListener in the code:
listener_layout = new OnClickListener(){
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "hi", Toast.LENGTH_SHORT);
}
};
call_layout = (LinearLayout) findViewById(R.id.call_layout);
call_layout.setOnClickListener(listener_layout);
but it never get fired…Any suggestions?
You didn’t call
show()on your toast, which seems like your listener doesn’t fire.The above line should be: