I am using ListView for making this layout(ScreenShot). Here when I click Button 1st, it is not worked. But if I click ListItem 1st then I click Button it works.
Even I used android:descendantFocusability="blocksDescendants" in the layout.
android:focusable="false" & android:focusableInTouchMode="false" inside of Button. But nothing worked.
Please help me to fix it.
My Codes:
xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardlist_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/curved_shape"
android:orientation="vertical"
card_view:cardElevation="7dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="horizontal">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="14dp"
android:layout_marginRight="14dp"
android:src="#drawable/image_4" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="14dp"
android:orientation="vertical">
<TextView
android:id="#+id/cartProduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Fusce veh"
android:textColor="#9F9F9F" />
<TextView
android:id="#+id/cartQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="100 g"
android:textColor="#9F9F9F" />
<LinearLayout
android:layout_width="225dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/symbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Rs "
android:textColor="#9F9F9F" />
<TextView
android:id="#+id/cartPrice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="8dp"
android:layout_weight="0.48"
android:text="19.99"
android:textColor="#9F9F9F" />
<TextView
android:id="#+id/cartPriceDum"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="8dp"
android:layout_weight="0.48"
android:text="19.99"
android:textColor="#9F9F9F"
android:visibility="gone" />
<ImageView
android:id="#+id/ivDecrease"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0.1"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="#drawable/ic_action_expand" />
<TextView
android:id="#+id/cartCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_weight="0.2"
android:gravity="center"
android:text="1"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ivIncrease"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="#drawable/ic_action_collapse" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#E4E4E4" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F8F8F8"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/addTowish"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#F8F8F8"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="ADD TO WISHLIST"
android:textColor="#787878" />
<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#E4E4E4" />
<Button
android:id="#+id/remove"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#F8F8F8"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="REMOVE"
android:textColor="#787878" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
You have to add clicklistener to your button inside adapter class
public DataObjectHolder(View itemView) {
super(itemView);
CardView cardClick = (CardView) itemView.findViewById(R.id.xxx);
btn = (Button) itemView.findViewById(R.id.xxx);
Log.i(LOG_TAG, "Adding Listener");
cardClick.setOnClickListener(this);
btn.setOnClickListener(this);
}
Please remove android:focusable="false" and android:focusableInTouchMode="false" from both your buttons.
Since you have disabled focusability it doesn't react on click the first time. When you click on the listview the row gains focus and hence its working.
Also remove android:descendantFocusability="blocksDescendants" from the linear layout that holds the buttons.
Related
I have a child recyclerview inside a parent recyclerview.Only the last item of parent recyclerview shows child recyclerview.For a better understanding look at the picture click here to see image
In Adapter class I already use customlayoutmanager but not a single solution will fix my problem.Inside adapter OnBindViewHolder method java code
holder.replyRecyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new CustomLinearLayoutManager(mContext);
holder.replyRecyclerView.setLayoutManager(layoutManager);
layoutManager.isAutoMeasureEnabled();
commentReplyList = new ArrayList<>();
commentReplayAdapter = new CommentReplyAdapter(mContext,commentReplyList);
holder.replyRecyclerView.setAdapter(commentReplayAdapter);
readCommentReply(comment.getCommentId(),holder.viewRepliesTV);
My parent_layout_item xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/commentImageProfile"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentStart="true"
android:layout_marginStart="12dp"
android:layout_marginTop="5dp"
android:contentDescription="#string/image" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/commentImageProfile"
android:orientation="vertical">
<LinearLayout
android:id="#+id/commentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
android:orientation="vertical"
android:paddingStart="2dp"
android:paddingTop="4dp"
android:paddingEnd="4dp"
android:paddingBottom="2dp">
<TextView
android:id="#+id/commentUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:textSize="13sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="#+id/commentReaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:background="#drawable/ic_comment_love" />
<TextView
android:id="#+id/commentLoves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="#+id/replyTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="Reply"
android:textSize="12sp" />
<TextView
android:id="#+id/commentTime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="12dp"
android:layout_weight="1"
android:gravity="end"
android:text="1d"
android:textSize="12sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/replyView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<EditText
android:id="#+id/sendReplyET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:background="#drawable/comment_reply_background"
android:inputType="textMultiLine"
android:padding="8dp"
android:paddingStart="8dp"
android:paddingEnd="35dp"
android:textSize="13sp" />
<ImageView
android:id="#+id/sendReply"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="5dp"
android:padding="5dp"
android:src="#drawable/ic_send_reply_twenty_padding" />
</RelativeLayout>
</LinearLayout>
<TextView
android:id="#+id/viewRepliesTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="6dp"
android:textSize="12sp"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/replyRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:paddingStart="40dp"
android:paddingEnd="1dp" />
</LinearLayout>
I would suggest using this library. You can have multi-level RecyclerViews. Here is a preview of the result.
I'm making a design in android using simple LinearLayout I create a TextView inside CardView when I enter long text inside TextView it hides some of the text, why this is happening? Check below image
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/universal_padding"> <!-- 8dp -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical">
<ImageView
android:id="#+id/ivCommentProfilePic"
android:layout_width="#dimen/card_profile_pic_width_height"
android:layout_height="#dimen/card_profile_pic_width_height"
app:srcCompat="#drawable/circular_photo" />
<ImageView
android:id="#+id/ivCommentUserBadge"
android:layout_width="#dimen/badge_width_height"
android:layout_height="#dimen/badge_width_height"
android:layout_marginTop="10dp"
android:layout_marginLeft="-10dp"
android:layout_marginStart="-10dp"
app:srcCompat="#drawable/shap_circle_badge" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/tvCommentUserFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"
android:textColor="#color/colorPrimaryText"
android:text="Azeem Haider" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:text=" - 2d"/>
</LinearLayout>
<TextView
android:id="#+id/tvCommentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:text="This is a comment for testing purpose This is a comment for testing purpose This is a comment for testing purpose"
/>
</LinearLayout>
</LinearLayout>
Try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="#+id/ivCommentProfilePic"
android:layout_width="96dp"
android:layout_height="96dp"
app:srcCompat="#drawable/kid" />
<ImageView
android:id="#+id/ivCommentUserBadge"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="-10dp"
android:layout_marginStart="-10dp"
android:layout_marginTop="10dp"
app:srcCompat="#drawable/ic_online" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="8dp"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/tvCommentUserFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Azeem Haider"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" - 2d" />
</LinearLayout>
<TextView
android:id="#+id/tvCommentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is a comment for testing purpose This is a comment for testing purpose This is a comment for testing purpose" />
</LinearLayout>
</LinearLayout>
OUTPUT
I am developing an android project where i have to implement A gridView with a upper horizontal scroll view panel. When i put only gridView in the layout "onitemclicklistener" is working as expected but when i put both horizontal scroll view and gridview then "OnItemclickListener " is not working properly.It is selecting different item while clicking on a item. After debugging i found it is not selecting correct position. My layout xml code like below
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/picUpperLayout"
android:layout_marginBottom="20dp"
android:gravity="center_vertical">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/picNavigationButton" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Picture"
android:id="#+id/picTitle"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:layout_marginLeft="20dp" />
</LinearLayout>
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/horizontalScrollView"
android:background="#000000"
android:layout_below="#+id/picUpperLayout"
android:focusable="false"
android:focusableInTouchMode="false">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Picture of\n The Week"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:id="#+id/pic_pictureOfTheWeek"
android:textColor="#ffffff"
android:lines="2" />
<ImageView
android:layout_width="match_parent"
android:layout_height="7dp"
android:id="#+id/pic_picoftheweekImage"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Bangladeshi\n Celebrity"
android:id="#+id/pic_b_celebrity"
android:textColor="#FFFFFFFF" />
<ImageView
android:layout_width="match_parent"
android:layout_height="7dp"
android:id="#+id/pic_b_celebrity_imageview"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Bollywood\nCelebrity"
android:id="#+id/pic_bolly_celebrity"
android:textColor="#FFFFFFFF" />
<ImageView
android:layout_width="match_parent"
android:layout_height="7dp"
android:id="#+id/pic_bolly_celebrity_imageiview"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Cool"
android:id="#+id/pic_cool"
android:textColor="#FFFFFFFF" />
<ImageView
android:layout_width="match_parent"
android:layout_height="7dp"
android:id="#+id/pic_cool_imageview"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Hollywood\nCelebrity"
android:id="#+id/pic_holly_celebrity"
android:textColor="#FFFFFFFF" />
<ImageView
android:layout_width="match_parent"
android:layout_height="7dp"
android:id="#+id/pic_holly_celebrity_imageView"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Love"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:id="#+id/pic_love"
android:singleLine="false"
android:textColor="#FFFFFFFF" />
<ImageView
android:layout_width="match_parent"
android:layout_height="7dp"
android:id="#+id/pic_love_imageView"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Speacial\nEvents"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:id="#+id/pic_speacial_events"
android:textColor="#FFFFFFFF" />
<ImageView
android:layout_width="match_parent"
android:layout_height="7dp"
android:id="#+id/pic_speacial_event_imageView"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Sticker"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:id="#+id/pic_sticker"
android:textColor="#FFFFFFFF" />
<ImageView
android:layout_width="match_parent"
android:layout_height="7dp"
android:id="#+id/pic_sticker_imageView"
android:layout_marginTop="5dp" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/horizontalScrollView">
<GridView
android:id="#+id/gridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"
android:horizontalSpacing="2dp"
android:clickable="true"
android:layout_marginTop="20dp" />
</LinearLayout>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:layout_centerInParent="true"
android:visibility="gone"/>
</RelativeLayout>
and my onitemclickevent code is
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Get item at position
PictureGridItemModel item = (PictureGridItemModel) parent.getItemAtPosition(position);
Intent intent = new Intent(PictureGridViewActivity.this, PictureDetailsActivity.class);
ImageView imageView = (ImageView) v.findViewById(R.id.grid_item_image);
int[] screenLocation = new int[2];
imageView.getLocationOnScreen(screenLocation);
Log.d("screenLocation", String.valueOf(screenLocation));
Log.d("screenLocation",String.valueOf(imageView.getY()));
Log.d("screenPosition",String.valueOf(position));
//Pass the image title and url to DetailsActivity
intent.putExtra("left", screenLocation[0]).
putExtra("top", screenLocation[1]).
putExtra("width", imageView.getWidth()).
putExtra("height", imageView.getHeight()).
putExtra("title", item.getTitle()).
putExtra("image", item.getImage()).
putExtra("contentCode",item.getContent_code()).
putExtra("categoryCode",item.getCategoryCode()).
putExtra("contentName", item.getContent_name()).
putExtra("sContentType",item.getsContentType()).
putExtra("sPhysicalFileName",item.getsPhysicalFileName()).
putExtra("contentImg",item.getContent_img()).
putExtra("ZedID",item.getZedID());
startActivity(intent);
}
});
I can't understand why this is happening. please provide me a solution. Thanks in advance.
I Haven't got the answer. But which I did is call the ClickListener from the custom adapter and By calling ClickListener Item click is getting the correct position and worked properly as expected.
How can I add view (with linear layout id/linearlayout_tambahkeluhan can add automatically when I click button id/tambah_keluhan) in case that...the content in linearlayout_tambahkeluhan is id/layout_keluhan, id/layout_status, id/layout_tindakan...How the code in Java? anyone can help me? Thx before
<LinearLayout
android:id="#+id/linearlayout_tambahkeluhan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/layout_keluhan" >
<TextView
android:id="#+id/textView11"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:text="KELUHAN"
android:textColor="#color/blue" />
<TextView
android:id="#+id/textView12"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text=":"
android:textColor="#color/blue" />
<Spinner
android:id="#+id/spinner_keluhan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/layout_status" >
<TextView
android:id="#+id/textView13"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:text="STATUS"
android:textColor="#color/blue" />
<TextView
android:id="#+id/textView14"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text=":"
android:textColor="#color/blue" />
<Spinner
android:id="#+id/spinner_status"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/layout_tindakan" >
<TextView
android:id="#+id/textView15"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:text="TINDAKAN"
android:textColor="#color/blue" />
<TextView
android:id="#+id/textView16"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:text=":"
android:textColor="#color/blue" />
<EditText
android:id="#+id/editText_tindakan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:ems="10"
android:textColor="#color/black" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/button_tambahkeluhan"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#android:color/transparent"
android:onClick="onClick"
android:text="tambah keluhan"
android:textColor="#color/blue"
android:textStyle="italic" />
You try addView(View view) function) with view can be controls or xml layout.
Example: ((LinearLayout)findViewById(R.id.linearlayout_tambahkeluhan)).addView(btnNew);
Add to your linearLayout visibility 'gone' like this:
<LinearLayout
android:id="#+id/linearlayout_tambahkeluhan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
Then in onCreate function in your Activity do this:
LinearLayout yourLinearLayout=(LinearLayout)findViewById(R.id.linearlayout_tambahkeluhan);
Button yourButton = (Button)findViewById(R.id.button_tambahkeluhan);
yourButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
yourLinearLayout.setVisibility(View.Visible);
}
}
I've made the next xml layout for listview item -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#drawable/back_item"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView_bot"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:src="#drawable/tv_ico" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView_saying"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:layout_marginTop="15dp"
android:ellipsize="end"
android:singleLine="true"
android:text="blah blah"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="18sp" />
<TextView
android:id="#+id/textView_nar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="sport"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textSize="15sp" />
<TextView
android:id="#+id/textView_clicks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:textColor="#696969"
android:text="Clicks"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<Button
android:id="#+id/button_add_item"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:background="#drawable/add_state"
android:focusable="false" />
</LinearLayout>
</LinearLayout>
Well, when I'm using this xml layout and pressing on a listview item all is fine - the code gets into the onItemClick.
But when I adding to this layout an ImageButton I'm not able to get into the onItemClick function.
Here's the full layout code with the ImageButton -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#drawable/back_item"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView_bot"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:src="#drawable/tv_ico" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView_saying"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:layout_marginTop="15dp"
android:ellipsize="end"
android:singleLine="true"
android:text="blah blah"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="18sp" />
<TextView
android:id="#+id/textView_nar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="sport"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textSize="15sp" />
<TextView
android:id="#+id/textView_clicks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:textColor="#696969"
android:text="Clicks"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<Button
android:id="#+id/button_add_item"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:background="#drawable/add_state"
android:focusable="false" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/clip_ico"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>
As you can see I've used android:focusable="false" but still not able to get into the onItemClick.
Any ideas why it happens?
Thanks for any kind of help
add android:descendantFocusability="blocksDescendants" in the root layout
enter code here
if you are suing custom Adpter for Listview
then
do it in you customadapter - getView method
ImageView YOURIMAGE=(ImageView) InflatedVIEW.findViewById(R.id.imageview1);
YOURIMAGE.setOnClickListener(new OnClickListener() {
#Override`
public void onClick(View v) {
}