how i can show and hide button in click on spinner android - java

i have spinner and 3 item video and photo and text and 4 button how i can show button if spinner select :
0
dow
favorite
Im trying to show a hidden button with spinner click
this is the cod
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/activity_secim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.rdvanayan.yeni.Secim"
android:background="#android:color/holo_green_light">
<TextView
android:text="Bir seçim yapınız"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#000000"
android:background="#ffffff"
/>
<Button
android:text="KAYDET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/kad1"
android:textStyle="normal|bold|italic"
android:textSize="18sp"
android:layout_marginTop="22dp"
android:layout_below="#+id/editText7"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:layout_alignParentEnd="true" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner"
android:layout_marginTop="12dp"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_below="#+id/kad1"
android:weightSum="1"
android:id="#+id/linearLayout2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/camera1"
android:layout_width="110dp"
android:layout_height="78dp"
android:layout_marginRight="100dp"
android:scaleType="centerInside"
android:visibility="invisible"
app:srcCompat="#drawable/camera" />
<ImageButton
android:layout_width="111dp"
android:layout_height="78dp"
app:srcCompat="#drawable/galll"
android:id="#+id/imageButton9"
android:scaleType="centerInside"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:layout_alignParentEnd="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="URL İNDİR "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button5"
android:layout_below="#+id/imageButton9"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:layout_alignParentEnd="true" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<ImageButton
android:id="#+id/imageButton11"
android:layout_width="wrap_content"
android:layout_height="78dp"
android:visibility="invisible"
android:layout_marginRight="90dp"
android:onClick="dispatchTakeVideoIntent"
android:scaleType="centerInside"
app:srcCompat="#drawable/video_kamera" />
<ImageButton
android:layout_width="111dp"
android:layout_height="78dp"
app:srcCompat="#drawable/video_galeri"
android:id="#+id/imageButton12"
android:scaleType="centerInside"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:layout_alignParentEnd="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="URL İNDİR "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button4"
android:layout_below="#+id/imageButton9"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:layout_alignParentEnd="true" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editText7"
android:hint="BAŞLIK"
android:visibility="invisible"
android:textStyle="normal|bold|italic"
android:textSize="20sp"
android:layout_below="#+id/spinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#000000"
android:background="#ffffff"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editText8"
android:textSize="20dp"
android:hint="AÇIKLAMA"
android:textStyle="normal|bold|italic"
android:textColor="#000000"
android:background="#ffffff"
android:layout_below="#+id/editText7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:visibility="invisible"
android:layout_marginTop="11dp" />
<ImageView
android:id="#+id/igm"
android:layout_width="50dp"
android:layout_height="32dp"
app:srcCompat="#drawable/son"
android:layout_below="#+id/editText8"
android:layout_alignRight="#+id/editText8"
android:layout_alignEnd="#+id/editText8"
android:layout_marginRight="55dp"
android:layout_marginEnd="55dp" />
</RelativeLayout>
and this is spinner item
<string-array name="secim">
<item> YAZI </item>
<item> RESİM </item>
<item> VİDEO </item>
</string-array>
Any help would be appreciated.

You have to show and hide buttons on spinner selection in your Activity class. Set "OnItemSelectedListener" to your spinner, it will override few methods. In overridden "OnItemSelected" method hide the button like this:
yourButton.setVisibility(VISIBILTY.GONE);

I would like to add the previous answer as a comment. But the reputation is inadequate.
Actually it should be like this:
Use for hide: resimButonu.setVisibility(View.GONE);
or resimButonu.setVisibility(INVISIBLE);
use for show: resimButonu.setVisibility(View.VISIBLE); or resimButonu.setVisibility(VISIBLE);

thanks but i have 4 button and text i need :
if RESİM selected show 2 button
if * YAZI * selected show textbox
if *VİDEO * selected show 2 button
i have 4 button in app
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.secim, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
camerax.setVisibility(View.VISIBLE);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}

Related

Button setonclick listener is not working correctly

when I press the save button does not work after pressing it several time button is working sometimes first-time press is working sometimes after pressing moreover 10 times button is not working.Also i have toast messege to determine it is working or not the toast messege appear after pressing several time to the button.
binding.savebtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(Settringsactivity.this,"ok",Toast.LENGTH_LONG).show();
String status=binding.etStatus.getText().toString();
String username=binding.etUsername.getText().toString();
HashMap<String, Object> obj=new HashMap<>();
Toast.makeText(Settringsactivity.this,username,Toast.LENGTH_LONG).show();
obj.put("username",username);
obj.put("about",status);
if(name!=null) {
Toast.makeText(Settringsactivity.this,"Updated",Toast.LENGTH_LONG).show();
database.getReference().child("Users").child(name).updateChildren(obj);
}
}
});
Here is the xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/savebtn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#color/white"
android:foregroundTint="#B11B1B"
tools:context=".Settringsactivity">
<ImageView
android:id="#+id/settingsbackarraow"
android:layout_width="30dp"
android:layout_height="30dp"
android:backgroundTint="#FFFFFF"
app:srcCompat="#android:drawable/checkbox_on_background" />
<LinearLayout
android:id="#+id/flinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/settingsbackarraow"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profileimage"
android:layout_width="120dp"
android:layout_height="120dp"
android:backgroundTint="#FFFFFF"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp"
android:src="#drawable/img" />
<ImageView
android:id="#+id/plus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/btn_plus" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#100606" />
<EditText
android:id="#+id/etUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#color/black"
android:hint="Enter your name"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:textColor="#100606" />
<EditText
android:id="#+id/etStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="About"
android:textColor="#color/black"
android:inputType="textPersonName" />
</LinearLayout>
<Button
android:layout_width="100dp"
android:layout_height="50dp"
android:elevation="15sp"
android:background="#1966FB"
android:layout_gravity="right"
android:text="Save" />
</LinearLayout>
</RelativeLayout>

Android textview text underline unwanted

I'm having a strange trouble and didn't find any solutions on the web.
I'm adding a TextView dynamically into a RelativeLayout, with custom fonts, and sometimes the text appears underlined.
public void bouton_valide_ajout_texte(View v)
{
new_text_view.setText(((TextView) dialog.findViewById(R.id.edit_ajoute_texte)).getText());
RelativeLayout rl_newtext_1 = (RelativeLayout)findViewById(R.id.rl_newtext_1);
rl_newtext_1.addView(new_text_view);*/
TextView text_view = new TextView(this);
text_view.setText(((TextView) dialog_ajoute_texte.findViewById(R.id.edit_ajoute_texte)).getText());
ListView liste_view_police = (ListView) dialog_ajoute_texte.findViewById(R.id.list_view_dialog_polices);
text_view.setTextSize(TypedValue.COMPLEX_UNIT_SP,12);
text_view.setTypeface(listePolices.get_typeface(position_item_police));
text_view.setTextColor(Color.argb(255, 0, 0, 0));
text_view.clearComposingText();
container_calques.addView(text_view);
Object[] tab_calque = new Object[5];
tab_calque[0]="texte";
tab_calque[1]=text_view;
tab_calque[2]=12;
tab_calque[3]=0;
liste_calques.add(tab_calque);
calque_selectionne=liste_calques.size()-1;
text_view.setOnTouchListener(new TouchListener_calque(liste_calques.size()-1));
dialog_ajoute_texte.hide();
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ebm="http://schemas.android.com/apk/res-auto"
xmlns:sat="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<RelativeLayout
android:layout_width="300dp"
android:layout_height="350dp"
android:layout_gravity="center"
android:id="#+id/rl_container_tshirt">
<ImageView
android:id="#+id/tshirt_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/tee_shirt_blanc">
</ImageView>
<RelativeLayout
android:id="#+id/container_calques"
android:layout_width="120dp"
android:layout_height="220dp"
android:layout_marginLeft="88dp"
android:layout_marginTop="85dp"
>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/layout_reglages_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
>
<SeekBar
android:id="#+id/seekbar_taille"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="true"
android:max="40"
android:progress="20"
/>
<SeekBar
android:id="#+id/seekbar_rotation"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:layout_alignParentLeft="true"
android:max="360"
android:progress="180"
/>
<Button
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Supprimer"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:onClick="bouton_supprimer_calque"/>
<Button
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Couleur"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:onClick="bouton_choisir_couleur"/>
<Button
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Police"
android:layout_alignParentRight="true"
android:layout_marginRight="8dp"
android:layout_marginTop="80dp"
android:onClick="bouton_choisir_police"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
>
<Button
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="ajouter texte"
android:id="#+id/ajouter_calque"
android:onClick="bouton_ajoute_texte"/>
<Button
android:textSize="10sp"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="ajouter image"
android:id="#+id/ajouter_image"
android:onClick="bouton_ajoute_image"
android:layout_alignParentRight="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="enregistrer création dans galerie"
android:id="#+id/enregistrer_creation"
android:onClick="bouton_enregistrer_creation"
android:layout_below="#+id/ajouter_calque"
/>
</RelativeLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.view.ext.SatelliteMenu
android:id="#+id/menu_flottant_gauche"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:layout_margin="8dp"
sat:satelliteDistance="170dp"
sat:mainImage="#drawable/ic_launcher"
sat:totalSpacingDegree="90"
sat:closeOnClick="true"
sat:expandDuration="200"
/>
</FrameLayout>
</LinearLayout>
Solved
I replaced
text_view.setText(((TextView);
dialog_ajoute_texte.findViewById(R.id.edit_ajoute_texte)).getText());
By
text_view.setText(((EditText);
dialog_ajoute_texte.findViewById(R.id.edit_ajoute_texte)).getText().toString());
The possible underline could by the ListView as it puts a divider between its items. Look at this answer to get rid of the divider
Please make sure you don't have any inputType to your textview as follows
android:inputType="something"

How to access views from the programatically inflated layouts?

I have an activity in which I have inflated another layout. OnClick of next destination I am getting inflated a new layout. Now I want to remove the inflated layout. So I want to access the linear layout of remove from inside inflated layout. How can I access this??
Layout looks like this :
I have achieved to inflate layout and remove the first destination from parent which is a part of parent layout. Now I want to do same with inflated destination layout. onClick of remove the inflated layout should get removed.
Next_destination layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="#android:color/white"
android:id="#+id/LinearAddedDestination">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DESTINATION"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/shape"
android:gravity="right"
android:layout_gravity="center|right"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="80dp"
android:id="#+id/remove">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_clear_black_18dp"
android:layout_marginLeft="05dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="REMOVE"
android:layout_gravity="center"
android:layout_marginLeft="05dp"
android:textSize="14sp"
android:layout_marginRight="15dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:background="#drawable/line2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp"
android:layout_gravity="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/ic_chevron_right_black_24dp"
android:layout_marginEnd="10dp"
android:text="#string/Loc"
android:layout_gravity="center"
android:layout_marginTop="05dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:cursorVisible="false"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Street/Building/Place"
android:layout_marginStart="48dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginEnd="10dp"
android:hint="#string/LocationDetails"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginStart="48dp"
android:hint="#string/HouseDetails" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text="#string/additionalContact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:layout_marginTop="08dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginEnd="50dp"
android:layout_gravity="center"
android:visibility="gone"
android:layout_marginTop="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Name"
android:layout_gravity="center"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Phone"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/or"
android:layout_gravity="center"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="220dp"
android:layout_height="40dp"
android:background="#drawable/shape"
android:layout_gravity="center_horizontal">
<ImageButton
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/phone2"
android:layout_gravity="center"
android:layout_marginStart="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/addFromContacts"
android:layout_gravity="center"
android:layout_marginStart="20dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginLeft="48dp"
android:hint="#string/contact1"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginEnd="10dp"
android:hint="Instruction"
android:layout_gravity="center"
android:layout_marginLeft="10dp" />
</LinearLayout>
</LinearLayout>
Activity from on which the layout is inflated.
View newDestination;
ViewGroup parent;
nextDestination.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
removeDestination.setVisibility(View.VISIBLE);
newDestination = getLayoutInflater().inflate(
R.layout.next_destination_layout, addDestination, true);
}
});
removeDestination.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
parent = (ViewGroup)destination.getParent();
parent.removeView(destination);
}
});
How to achieve this?? Please help...
{ ll.removeView(view)// to remove particular view
ll.removeViewAt(position);// to remove view from particular position
}

Android: onClick event listener doesn't work on linearlayout

I am trying to implement an onclick for the entire layout but it won't work.
Here is my function for my RelativeLayout:
public void updateRange(View v)
{
System.out.println("Hello!");
}
and here is my xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity"
android:background="#ffffffff"
android:id="#+id/xasdf"
android:onClick="updateRange">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/toptab"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/settingsButton"
android:background="#fffdb64b" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Solutions"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/solutionsButton"
android:background="#fffdb64b" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mode"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.333333"
android:id="#+id/modeButton"
android:background="#fffdb64b" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/chartlayout"
android:layout_below="#+id/toptab"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/textView"
android:layout_weight="0.5"
android:background="#ffffffff"
android:fontFamily="monospace"
android:hint="y = ..." />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Graph"
android:fontFamily="monospace"
android:textAllCaps="false"
android:layout_weight="0.25"
android:id="#+id/button"
android:background="#ffd0d0d0"
android:onClick="drawGraph" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Table"
android:fontFamily="monospace"
android:layout_weight="0.25"
android:textAllCaps="false"
android:id="#+id/button2"
android:background="#ffd0d0d0" />
</LinearLayout>
</RelativeLayout>
Try adding the extra line below to your Relative Layout description:
...
android:onClick="updateRange"
android:clickable="true">

ListView row not clickable (after adding two buttons)

Strangely, my listView's onClick no longer works after I added two Buttons: Submit and Show Result.
Here is the list view xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".CulturalActivity"
android:background="#EFEFEF"
android:id="#+id/AdLayout"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="3dp"
>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:divider="#android:color/transparent"
android:descendantFocusability="blocksDescendants"
android:scrollbars="none"
android:dividerHeight="10dp"
android:listSelector="#drawable/list_selector" />
</RelativeLayout>
Here is the layout of each list row:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="315dp"
android:clickable="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="7dp"
android:background="#drawable/bg_card"
android:orientation="horizontal"
android:padding="5dip" >
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="-60dp"
android:background="#2093CD"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="52dp"
android:text="Audit"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout2" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Farm/Grp"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignTop="#+id/tile"
android:layout_toRightOf="#+id/textView4" />
<!--thumbnail-->
<LinearLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/thumbnail_image"
android:layout_marginTop="35dp"
android:gravity="center"
android:id="#+id/tile">
<ImageView
android:id="#+id/thumbImage"
android:layout_width="50dp"
android:clickable="false"
android:layout_height="50dp"
android:src="#drawable/opened" />
</LinearLayout>
<TextView
android:id="#+id/crophead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crop"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignBottom="#+id/tile"
android:layout_alignLeft="#+id/title" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Certification"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/certification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView2"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/title"
android:text="Test"
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Audit Type"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/tile"
android:layout_alignLeft="#+id/textView2"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/audittype"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignLeft="#+id/certification"
android:maxLines="2"
android:text="ES"
android:textColor="#343434"
android:textSize="17sp" />
<View
android:layout_width="fill_parent"
android:layout_height="3px"
android:layout_marginTop="200dp"
android:background="#21265b"
android:id="#+id/view" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/view"
android:layout_alignLeft="#+id/view"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="false" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginRight="15dp"
android:layout_alignTop="#+id/textView6"
android:layout_alignRight="#+id/startdate" />
<TextView
android:id="#+id/startdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="30/05/1992"
android:textSize="17sp"
android:layout_alignTop="#+id/enddate"
android:layout_toRightOf="#+id/relativeLayout2"
android:layout_marginLeft="6dp"
android:layout_alignParentBottom="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="2/13/14"
android:textSize="17sp"
android:id="#+id/enddate"
android:layout_below="#+id/textView7"
android:layout_alignRight="#+id/textView7" />
<TextView
android:id="#+id/farm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/audittype"
android:maxLines="3"
android:layout_alignTop="#+id/title"
android:text="Tea Estate Nagarcoil Tamil Nadu, India "
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/crop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/farm"
android:layout_alignTop="#+id/crophead"
android:maxLines="2"
android:text="Wheat without its chaff and barn but not brown"
android:textColor="#343434"
android:textSize="17sp" />
<Button
android:id="#+id/upsync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/blue_thumb"
android:layout_below="#+id/enddate"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Show Results"
android:textColor="#android:color/white" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/upsync"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_below="#+id/enddate"
android:background="#drawable/blue_thumb"
android:text="Submit"
android:textColor="#android:color/white" />
</RelativeLayout>
Here is the click snippet of the list view:
listview.setOnItemClickListener( new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
long audit_id;
try{
audit_id = (new CustomListAdapter(HomeList.this, c).getAuditID(position));
changeTileStatus(audit_id,"opened");
System.out.println("listClicked");
sendAuditAndIntent(audit_id);
}catch(Exception e)
{
System.out.println("ERROR # HOMELIST list onClick: "+e);
}
}
private void sendAuditAndIntent(long audit_id) { //sends audit id and api key
Intent intent = new Intent(HomeList.this,ChapterActivity.class );
Bundle extras= new Bundle();
extras.putString("audit_id",String.valueOf(audit_id));
extras.putString("api_key", api_key);
intent.putExtras(extras);
startActivity(intent);
}
private void changeTileStatus(long audit_id, String value) {
AuditTableManager tile= new AuditTableManager(HomeList.this);
tile.open();
tile.updateEntry(audit_id, value);
tile.close();
}
});
OnItemClickListener is not called if cells contain clickable Views. It is an Android feature. You can handle clicks by OnClickListener then - set it to your two buttons (not the listView itself).
In your adapter:
public View onCreateView(..., final int position){
...
convertView.findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction1(position);
}
});
convertView.findViewById(R.id.button2).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction2(position);
}
});
...
}
Try android:Focusable="false" and also android:clickable="false" in the custom row TextView

Categories

Resources