is a linear layout with in my ImageView (icon) and TextView ( "settings") in this way:
I like when the user clicks On LinearLayout or ImageView or TextView, another Actitivy has started.
If I do this in code:
OnClickListenerLessons mOnClickListener = new mOnClickListenerLessons () {@Override public void onClick (View v) {Intent i = new Intent (getActivity (), Next activity. Category); StartActivity (i); }} ImageView.setOnClickListener (mnClickListener); LinearLayout.setOnClickListener (mOnClickListener); TextView.setOnClickListener (mOnClickListener);
And I came to know that it is quite heavy and dirty, is there any code to make cleaner?
Many thanks!
PS: Here is my XML file
& lt; LinearLayout & gt; ... and & lt; LinearLayout android: id = "@ + id / linear_layout_wrapper_lessons" style = "@ style / width_height_margin_for_items" Android: layout_weight = "25" android: clickable = "true" android: gravity = "center" android: orientation = "horizontal" & Gt; & Lt; imageView android: id = "@ + id / lessons_icon" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" android: src = "@ drawable / puzzle_piece" / & gt; & Lt; TextView android: id = "@ + id / home_lesson_textView" style = "@ style / text_view" android: clickable = "true" android: text = "@ string / home_lesson_button" / & gt; & Lt; / LinearLayout & gt; ... & lt; / LinearLayout & gt;
here is text_view
for style.xml
When you set the onClickListener
to TextView
or imageView
, you should also declare it as the Android: clickable = "true"
or setClickable (true)
.
In addition to a is the LinearLayout
a imageView
and can not be TextView necesseary with a , that's why Do not you just add android: drawableLeft
with image? Nesting linear layout
is a very bad habit.
No comments:
Post a Comment