I have a RelativeLayout positioned over the rest of my view and I want this RelativeLayout to stop anything underneath it from being clicked. Here is my document outline:
FrameLayout
LinearLayout
RelativeLayout
The RelativeLayout only has a background colour, and has nothing inside it. The LinearLayout has buttons and textboxes in it. I want to stop people from being able to click on the buttons and textboxes if the RelativeLayout is visible.
You will need to consume the click. Find yourRelativeLayout and set an OnClickListener on it:
yourRelativeLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { }
});
In the xml file
android:clickable="false"
To do it in code:
LinearLayoutItem.setClickable(false);
Related
How can I set the visibility of a grid layout from INVISIBLE to VISIBLE in android studio.
Look at this what i'd tried-
public void verifyOTP(View view){ //verifyOTP is button onclick method
GridLayout gridLayout = (GridLayout) findViewById(R.id.gridLayout);
gridLayout.setVisibility(View.VISIBLE);
}
This doesn't worked for me. i.e. when i press the verifyOTP button, the layout is not reset to VISIBLE from INVISIBLE.
please suggest some solution.
I am working with android development and want to implement edittext in listview such like that in picture. now want to add this kind of implementation. is there any way to do exactly this thing or any library which is doing this work.any kind of help will be appreciated and thanks an advance.
It's pretty simple. I recommend you not to use listview to implement that. Just use LinearLayout with vertical orientation, and add each field when the "Add More" button item clicked.
LinearLayout parentLayout = (LinearLayout) findViewById(R.id.parent_layout); //make sure you have set vertical orientation attribute on your xml
TextView addMoreText = new TextView(context);
addMoreText.setText("Add More");
addMoreText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText editTextItem = new EditText(context);
parentLayout.addView(editTextItem, 0);
}
});
parentLayout.addView(addMoreText);
Note that the code above is just global picture of how to solve your problem. For implementation with close or add button on the right side, you may create custom view that holds EditText, ImageView based your own.
Hello my name is Fabian and at the moment I try to programming an Android App.
I have a ListView with some items and above this ListView I added a LinearLayout, which I want to make clickable, to add items to the ListView.
If I touch one entry in the ListView the item gets colorized with the default color, a light grey. I like to have this behaviour for my LinearLayout, too.
I know how to get the LinearLayout clickable.
I did this by
android:clickable="true"
android:onClick="addProject"
Also I know how to define the backgroundcolor, but I don't know how I can pass the default colors from android of the ListView (android:listSelector) to the LinearLayout.
I tested to define
android:background="?android:attr/listChoiceBackgroundIndicator"
but in that case the LinearLayout gets colorized blue and only if I touch it, it gets the right color.
I hope you can help me, to pass the default color of a ListView to a LinearLayout.
Remove below line from your LinearLayout
android:onClick="addProject"
and add an id to a LinearLayout,
android:id="#+id/linear_layout"
From JAVA add this,
LinearLayout layout = (LinearLayout) findViewById(R.id.linear_layout);
layout.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
Toast.makeText(this, "Layout Clicked", Toast.LENGTH_LONG).show();
}
});
I have two rows of imageViews in a ScrollView. The imageViews all have onClickListener and when i want to scroll in this area it doesn't work. So i guess the Click listeners intercept the scrolling of the ScrollView. What's the best way to change this behaviour ?
My View hierarchy is like this:
<ScrollView>
<RelativeLayout>
<FrameLayout>
</FrameLayout>
<RelativeLayout>
</ScrollView>
in the FrameLayout i put a Fragment which has a LinearLayout in which i inflate other LinearLayouts like this:
productHolder.productLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View v) {
}
});
Maybe you could use an OnTouchListener instead of an OnClickListener.
In the OnTouchListener you can check if the action of the motion event was a click and consume the event (return true). Otherwise you can leave the event for other listeners (return false) to consume.
Note, that you might need to add some additional implementation for figuring out which image view was clicked, however without seeing your layout, it's hard to give you a hint how to do it.
I have a ListView with custom list items. Each list item consists of 2 linear layouts one next to other.
LinearLayout 1 | LinearLayout 2 |
I've declared state list drawables for both LinearLayouts where in state_pressed I'm changing the background of the LinearLayout.
And here comes the issue - When the user taps on the LinearLayout2 only the background of LinearLayout2 should be changed, the background of LinearLayout1 should remain unchanged. On the other hand, when the user taps on LinearLayout1, only the background of LinearLayout1 should be changed. But now when the user taps on either of both LinearLayouts, both of them change their background.
The behaviour on tap on LinearLayout2 should be as onListItemClick() while when the user taps on LinearLayout1 a Dialog should appear (if this matters).
Any ideas how could I solve the background change issue? I've tried playing with focusable and clickable options. If i set clickable=true to both LinearLayouts, the children (TextViews) of LinearLayout2 do not change their colour (the TextViews should change their text colour).
Thank you!
This is because when using a list view you have to change some tags in XML to make the background transparent so that it will correctly work with your back ground.
Add this to your ListView XML code.
android:cacheColorHint="#00000000"
To set the ListView's background to transparent.
Well I think a single solution if you are using BaseAdapter as extends
First give unique Id to both those Layouts in you xml file and add
android:clickable="true"
In your method
public View getView(int position, View convertView, ViewGroup parent) {
when your are getting those views like
holder.layout1_name=(LinearLayout)view.findViewById(R.id.layout1);
holder.layout1_name.setOnClickListener( clicklayout1);
holder.layout2_name=(LinearLayout)view.findViewById(R.id.layout2);
holder.layout2_name.setOnClickListener( clicklayout2);
Add click listener on them
private OnClickListener clicklayout1 = new OnClickListener() {
public void onClick(View v) {
//Do what you want to do here
}
};
private OnClickListener clicklayout2 = new OnClickListener() {
public void onClick(View v) {
//Do what you want to do here
}
};
May be this may help you