I have read through other posts. I can't able to find the solution still.
I tried putting
android:focusableInTouchMode="false"
android:focusable="false"
not worked.
I have included
android:clickable="true"
not worked.
In Java code, I have included
imgLeft.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
v.performClick();
}
}
});
aside with the onClickListener().
But still it didn't worked.
Here is my rough layout structure and position of the image view.
<RelativeLayout>
<FrameLayout>
<LinearLayout>
<Relativelayout>
<LineatLayout/>
<LinearLayout>
<LinearLayout>
<ImageView <--- This is the I needed to click.
android:id="#+id/imgLeft"
android:layout_width="wrap_content"
android:layout_height="#dimen/title_img_width"
android:src="#drawable/left"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</Relativelayout>
</LinearLayout>
</FrameLayout>
</Relativelayout>
I am using setOnClickListener for handling the click event.
imgLeft.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//some function here <-- **This function triggers only after the second click**
}
});
NOTE:
I thoroughly checked the other stackoverflow posts. But none of them solved the problem.. is there any solution for the above
UPDATE: Original code:
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_image" >
<FrameLayout
android:id="#+id/layoutConfiguration"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/bg_image"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/menu_header_height" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1" >
<LinearLayout
android:id="#+id/ll_menu"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="#dimen/menu_top_icon"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="5dp"
android:src="#drawable/menu" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.68"
android:fontFamily="Oswald-Regular.ttf"
android:gravity="center"
android:text="Connect Bluetooths"
android:textColor="#fff"
android:textSize="#dimen/menu_tital_textsize" />
<!-- android:padding="#dimen/menu_tital_padding" -->
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:gravity="center"
android:padding="15dp"
android:text=""
android:textColor="#fff"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll_sole"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/tital_margin_top"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_leftBattery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="100%"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/holo_red_dark"
android:textSize="16sp"
android:visibility="gone" />
<ImageView
android:id="#+id/imgLeftBluetooth"
android:layout_width="wrap_content"
android:layout_height="#dimen/title_img_width"
android:src="#drawable/left" />
<TextView
android:id="#+id/tv_leftBluetooth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="Not Connected"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_rightBattery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="100%"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/holo_red_dark"
android:textSize="16sp"
android:visibility="gone" />
<ImageView
android:id="#+id/imgRightBluetooth"
android:layout_width="wrap_content"
android:layout_height="#dimen/title_img_width"
android:layout_marginTop="5dp"
android:src="#drawable/right" />
<TextView
android:id="#+id/tv_rightBluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="Not Connected"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="#dimen/menu_tital_padding" >
<ToggleButton
android:id="#+id/toggleButton_connectBluetooth"
android:layout_width="#dimen/title_img_height"
android:layout_height="#dimen/title_text_height"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/toggle_selector"
android:checked="false"
android:padding="5dp"
android:text=""
android:textOff=""
android:textOn="" />
<TextView
android:id="#+id/tv_toggle_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="7dp"
android:text="Connect Left Bluetooths Only"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="#+id/fl_balloon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="-15dp"
android:gravity="center"
android:visibility="gone" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="#dimen/balloon_width"
android:layout_height="#dimen/balloon_height"
android:layout_gravity="center"
android:scaleType="fitXY"
android:src="#drawable/balloon" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:fontFamily="Oswald-Regular.ttf"
android:gravity="center"
android:text="Pair"
android:textColor="#android:color/white" />
</FrameLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:fontFamily="Oswald-Regular.ttf"
android:text="Configure Bluetooths"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="#dimen/menu_tital_textsize"
android:visibility="gone" />
<Button
android:id="#+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="#dimen/menu_top_icon"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="29dp"
android:background="#drawable/button_box"
android:padding="3dp"
android:text="Continue"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</RelativeLayout>
The id of the clicks that were performed are
imgLeftBluetooth and imgRightBluetooth. These two imageviews were triggering only after 2nd click.
Its simple .You can try this
Just add android:onClick="clicking" in your ImageView (XML)
Then
public void clicking(View v)
{
Toast.makeText(v.getContext(),"Clicking On Image",Toast.LENGTH_LONG).show();
}
Edited
YOUR_IMAGE_VIEW_OBJ.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Do your Staff
}
});
Android ImageView's onClickListener does not work
Related
I tried to search this question but no1 has answerd this, so here it is.
i am using a list view inside a scroll view.
when i am adding an onitemcliked listener to the listview it is not responding.
how to i get the listview access? i mean how do i get which position has been clicked. i know how it is normally done but inside a scroll view the listview is not reponding.
this is the code of adding onitemcliked listner to lisview.
itemlist.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(cv, "position:"+arg2, Toast.LENGTH_SHORT).show();
}
});
here is the xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:id="#+id/et_agent_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Agent Details"
android:textSize="18dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:src="#drawable/linedivider" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Agent"
android:textStyle="italic" />
<TextView
android:id="#+id/login_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LoginId"
android:textSize="15dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="Route" />
<Spinner
android:id="#+id/route_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<requestFocus />
</Spinner>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="Shop" />
<TextView
android:id="#+id/tvShopName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tv_shopaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="Address : " />
<Button
android:id="#+id/button_no_order"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="No Order" />
</LinearLayout>
<TextView
android:id="#+id/et2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Details"
android:textSize="18dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:src="#drawable/linedivider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etSearchBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
</EditText>
<Button
android:id="#+id/btn_SearchProduct"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Search" />
</LinearLayout>
<TableLayout
android:id="#+id/displayOrderTableView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<Button
android:id="#+id/button_order"
style="?android:attr/buttonStyleSmall"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Order"
android:textAlignment="inherit" />
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:src="#drawable/underline" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="#+id/button_clear"
style="?android:attr/buttonStyleSmall"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Clear"
android:textAlignment="inherit" />
<Button
android:id="#+id/button_submit"
style="?android:attr/buttonStyleSmall"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Submit"
android:textAlignment="inherit" />
</LinearLayout>
</LinearLayout>
</ScrollView>
pleasde help me i am stuck on this.. it might be a very silly solution. but please help me
thank u in advance.
This is likely caused since that ScrollView is at higher level than the ListView in parent-child hierarchy. So that ScrollView can absorb touch events at its own level and does not pass them to its children. This results in the ListView will not get touch events at all and subsequently does not respond to onItemClicked.
The solution is here.
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 have a relative layout with an image and title.Below the relativelayout I have an Editext(used for searching which will display a search result listview based on change of text in the edittext).So once i touch on the EDITExt softkeyboard will appear and the top layout's visibility is set to 'Gone'.It works fine but sometimes the edittext moves up but the top layout is visible like ui frozen and this will disapppear when we enter a keystroke for edittext.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/violetbg"
android:id="#+id/parentt"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/framestepone"
/>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#+id/framestepone"
>
<RelativeLayout
android:layout_height="#dimen/titlebarsize"
android:layout_width="match_parent"
android:background="#color/red"
android:layout_alignParentTop="true"
android:id="#+id/topbar"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
style="#style/actionbarphonetextviewstyle"
android:text="#string/steponetitle"
android:id="#+id/steponetitle"
/>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/sidemenutest"
android:id="#+id/sidemenu"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:background="#null"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/initlay"
android:layout_height="wrap_content"
android:layout_below="#+id/topbar"
android:layout_marginTop="3dp"
android:layout_width="match_parent">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/layyy"
>
<TextView
android:layout_centerHorizontal="true"
android:id="#+id/steptag"
android:text="#string/steptagg"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="#dimen/titletextsize"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="30dp"
/>
<TextView
android:layout_centerHorizontal="true"
android:id="#+id/steponetag"
android:text="#string/onetag"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="#dimen/titletextsize"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/steptag"
android:layout_marginTop="5dp"
/>
<ImageView
android:id="#+id/steponebg"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/stepone"
android:layout_below="#+id/steponetag"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_centerHorizontal="true"
android:id="#+id/steponetext"
android:text="#string/chooser"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="#dimen/titletextsize"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/steponebg"
android:textAllCaps="true"
android:layout_marginTop="20dp"
/>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativebag"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#+id/initlay"
android:layout_marginTop="10dp"
android:focusableInTouchMode="true"
>
<RelativeLayout
android:id="#+id/relativebagforlist"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_centerHorizontal="true"
>
<EditText
android:layout_height="60dp"
android:layout_width="match_parent"
android:hint="Search & Preview Song"
android:id="#+id/searchsong"
android:inputType="textNoSuggestions"
android:textColor="#color/black"
android:textSize="#dimen/text_size_small"
android:background="#drawable/steponetextboxbg"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:singleLine="true"
android:paddingLeft="12dp"
android:imeOptions="actionDone"
android:paddingRight="8dp"
/>
<RelativeLayout
android:layout_height="60dp"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:background="#drawable/steponetextboxbg"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:visibility="gone"
android:id="#+id/parntrecrd"
>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:id="#+id/lay"
android:layout_marginLeft="10dp"
>
<ImageButton
android:id="#+id/playbtns"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/play"
android:background="#null"
android:layout_centerVertical="true"
android:paddingLeft="5dp"
/>
<ImageButton
android:id="#+id/pausebtns"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/pause"
android:background="#null"
android:layout_centerVertical="true"
android:paddingLeft="5dp"
android:visibility="gone"
/>
</RelativeLayout>
<TextView
android:id="#+id/txtsearche"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toRightOf="#+id/lay"
android:background="#color/white"
android:clickable="true"
android:gravity="center_vertical"
android:hint="search song"
android:inputType="none"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#color/black"
android:textSize="#dimen/text_size_small" />
</RelativeLayout>
</RelativeLayout>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/question"
android:background="#null"
android:layout_below="#+id/relativebagforlist"
android:layout_alignRight="#+id/relativebagforlist"
android:layout_marginTop="5dp"
android:id="#+id/btnhelp"
android:layout_marginRight="10dp"
/>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignTop="#+id/btnhelp"
android:layout_alignBottom="#+id/btnhelp"
android:layout_toLeftOf="#+id/btnhelp"
android:layout_marginRight="5dp"
android:layout_below="#+id/relativebagforlist"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/hlptxt"
android:layout_marginTop="5dp"
android:text="#string/help"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<Button
android:layout_height="#dimen/btnheights"
android:layout_width="match_parent"
android:text="#string/readybutton"
android:id="#+id/btnready"
android:textColor="#color/white"
android:background="#drawable/buttonbackground"
style="#style/actionbarphonetextviewstyle"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:textAlignment="center"
/>
<ListView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/lstsongs"
android:background="#color/white"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:visibility="gone"
android:clickable="true"
android:layout_marginTop="10dp"
android:layout_below="#+id/relativebagforlist"
/>
<TextView
android:layout_height="60dp"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:visibility="gone"
android:layout_below="#+id/relativebagforlist"
android:background="#color/white"
android:text="#string/nomatch"
android:id="#+id/nomatchtext"
android:textColor="#color/black"
android:paddingLeft="10dp"
android:gravity="center_vertical"
/>
</RelativeLayout>
<!-- ******************************************** -->
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/progrest"
android:visibility="gone"
android:layout_centerInParent="true"
/>
</RelativeLayout>
</RelativeLayout>
and my code after clicking the textview which will invoke the softkeyboard making the edittext visible and top layout gone is as follows
txtsearch.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
temptext=(txtsearch.getText().toString());
help.setVisibility(View.GONE);
helptext.setVisibility(View.GONE);
txtrecord.setVisibility(View.GONE);
searchsong.setVisibility(View.VISIBLE);
steptag.setVisibility(View.GONE);
steponetag.setVisibility(View.GONE);
steponebg.setVisibility(View.GONE);
steponetext.setVisibility(View.GONE);
lay.setVisibility(View.GONE);
searchsong.requestFocus();
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(searchsong, InputMethodManager.SHOW_FORCED);
searchsong.setText(temptext);
if(myMap.size()==0){
new Getsongs().execute();
}
}
});
I solved it by removing android:windowSoftInputMode="adjustResize|stateHidden"
from my manifest
I need to set a part of my layout dynamically the number of times i receive a value of data.
For example if receive data=3 I want that my same layout part appears three times but rest of the layout remains same.
I tried inflating it but then it overlaps on my rest of the layout.
This is the layout I want to add recursively.
link.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/offers"
android:layout_below="#id/visits_remaining"
android:layout_height="wrap_content"
android:layout_width="match_parent" >
<TextView
android:id="#+id/tier_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Outlet Offer"/>
<TextView
android:id="#+id/tier_visits"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="1 - 5 visits"/>
<TextView
android:id="#+id/tv1"
android:layout_below="#id/tier_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Hello"/>
<ImageView
android:id="#+id/v1"
android:layout_below="#id/tier_name"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:src="#drawable/arrow" />
<TextView
android:id="#+id/tv2"
android:layout_below="#id/tv1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="World"
android:visibility="gone"/>
<TextView
android:id="#+id/tv3"
android:layout_below="#id/tv2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="World"
android:visibility="gone"/>
<TextView
android:id="#+id/tv4"
android:layout_below="#id/tv3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="World"
android:visibility="gone"/>
<TextView
android:id="#+id/tv5"
android:layout_below="#id/tv4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="World"
android:visibility="gone"/>
</RelativeLayout>
This is the layout in which I want to add it above last two buttons.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/outlet_names"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="14dp"
android:textSize="25sp"
android:text="Outlet Name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View
android:id="#+id/rule"
android:layout_below="#id/outlet_names"
android:layout_width="fill_parent"
android:layout_marginTop="10dp"
android:layout_height="0.02mm"
android:background="#ffe6e1d4" />
<TextView
android:id="#+id/address"
android:layout_marginTop="10dp"
android:layout_below="#id/rule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:hint="address" />
<TextView
android:id="#+id/landline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/address"
android:textSize="15sp"
android:autoLink="phone"
android:hint="landline" />
<TextView
android:id="#+id/mobile1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/address"
android:layout_toRightOf="#id/landline"
android:layout_marginLeft="5dp"
android:textSize="15sp"
android:autoLink="phone"
android:hint="mobile"/>
<ImageView
android:id="#+id/outlets"
android:layout_below="#id/mobile1"
android:layout_height="100dp"
android:layout_marginTop="7dp"
android:layout_width="match_parent"/>
<TextView
android:id="#+id/prog_name"
android:layout_below="#id/outlets"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textSize="15sp"
android:text="Program Name" />
<TextView
android:id="#+id/validity"
android:layout_below="#id/prog_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textSize="15sp"
android:text="Program ends :"/>
<TextView
android:id="#+id/end"
android:layout_below="#id/prog_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:text="Aug 5,2014"
android:textSize="15sp" />
<ProgressBar
android:id="#+id/progress"
android:layout_below="#id/validity"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="10dp"/>
<TextView
android:id="#+id/visits_remaining"
android:layout_below="#id/progress"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="2 visits to go for the next reward"/>
<Button
android:id="#+id/more"
android:layout_below="#+id/offers2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="See more" />
<Button
android:id="#+id/terms"
android:layout_below="#id/more"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Terms and Conditions" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
place a ViewGroup in where you want in xml and add your view to it dynamically.
onclick a button or... below function call
final View addedView = getLayoutInflater().inflate(R.layout.someId,
yourViewGroup, false);
Button btn= (Button) addedView.findViewById(R.id.someId);
ImageButton imgBtn= (ImageButton) addedView.findViewById(R.id.someId);
addedView .setTag("a unique id");
btn.setText("click me to do something");
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
int thisViewId = (Integer) addedView.getTag();//use this for indicate which view is click
//do some thing
}
});
imgBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
yourViewGroup.removeView(addedView);//delete just this addedView
}
});
yourViewGroup.addView(addedView);
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main" />
<!--some tags here-->
<HorizontalScrollView
android:id="#+id/doc_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#cccccc" >
<LinearLayout
android:id="#+id/table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:animateLayoutChanges="true">
<!--views will add here-->
</LinearLayout>
</HorizontalScrollView>
<!--some tags here-->
</RelativeLayout>
addedView.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:gravity="center_vertical"
android:background="#eee" >
<Button
android:id="#+id/chapter_page"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="" />
<ImageButton
android:id="#+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_delete"
android:background="#00000000" />
</LinearLayout>
if use above code you will see your Horizontal view get child on every time run function.
Take linear layout on above button
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/outlet_names"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="Outlet Name"
android:textSize="25sp" />
<View
android:id="#+id/rule"
android:layout_width="fill_parent"
android:layout_height="0.02mm"
android:layout_marginTop="10dp"
android:background="#ffe6e1d4" />
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="address"
android:textSize="15sp" />
<TextView
android:id="#+id/mobile1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:hint="mobile"
android:textSize="15sp" />
<ImageView
android:id="#+id/outlets"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="7dp" />
<TextView
android:id="#+id/prog_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Program Name"
android:textSize="15sp" />
<TextView
android:id="#+id/validity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Program ends :"
android:textSize="15sp" />
<TextView
android:id="#+id/end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Aug 5,2014"
android:textSize="15sp" />
<ProgressBar
android:id="#+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/visits_remaining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="2 visits to go for the next reward" />
<LinearLayout
android:id="#+id/linDynamic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/more"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="See more" />
<Button
android:id="#+id/terms"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Terms and Conditions" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
write in your main activty
linDynamic = (LinearLayout) mView.findViewById(R.id.linDynamic);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
for (int i = 0; i < 4; i++)
{
TextView txtDemo = new TextView(getActivity());
txtDemo .setTextSize(16);
txtDemo .setLayoutParams(lp);
txtDemo .setId(i);
lp.setMargins(0, 10, 0, 0);
txtDemo .setPadding(20, 10, 10, 10);
txtDemo .setText("Text View"+ i);
linDynamic .addView(txtDemo );
}
}
Add the ScrollView below where you want (in your case below the two buttons)
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="#+id/add_dynamic_layout_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
/>
</ScrollView>
Then add the layout dynamically through code
//add dynamic layout below to the clicked layout
final RelativeLayout newView = (RelativeLayout)getLayoutInflater().inflate(R.layout.dynamic_layout, null);
newView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
dynamicLayoutContainer.addView(newView);
ImageView removeView = (ImageView)dynamicLayoutContainer.findViewById(R.id.dynamic_image_remove);
removeView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dynamicLayoutContainer.removeView(newView);
}
});
I hope this will help you.
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) {
}