Prevent from Duplicating a View on Custom ListView Layout - android

I created a layout which has a button. I want to prevent from duplicating the button for each row while I'm using the layout to inflate. How should I do that?
Thanks,
Alireza

I'm not sure what you mean by "inflate" but the button is in the schema of the layout so that has to be taken out of the scope of that tag. Then, you can define another section (container) and have one button per container. If you add more details to your question, I'll elaborate

Related

How to remove a custom view and rearrange linear layour

First of all I will explain my scenario.
I have an activity with a linear layout and I am inflating that linear layout with custom views. In the custom view I have a remove button to remove the particular child.
I know to remove the view I have to add an onClick Listener to the button in the custom view. But what I am not sure about is that how can I remove the view from its parent view from that onClick Listener.
I am populating the linear layout from items stored in shared preferences. So I thought first to update the shared preference by removing the string of the particular custom view I am clicking. But I don't know how I cn manage to re-populate the linear layout, since the function is in the parent activity.
I am a complete newbie in android. Thanks in advance
update
I'll make the scenario a little more simple.
I have a custom view with two imagebuttons - update & remove.
If i click in the remove button, then the custom view should be removed from the linearlayout.
And if I click in the update imagebutton, a function of the Activity which hosts the Linearlayout should be called with the text in the customview as a parameter.
How can i do this. I tried many ways, but failed :-(
I found the answer finally :
For the first requirement, ie., to remove the view, I used:
LinearLayout parentLyt = (LinearLayout) RecentSearch.this.getParent();
parentLyt.removeView(RecentSearch.this);
Thanks Very much to Piyush Gupta (#piyush)
For the second option, to access the hosting activity, I used getContext() and casted it to my activity class, then called the method.
Thanks every one who replied.

Conditional widget visibility in layout XML

I'd just like to ask if it's possible for widgets to have conditional visibility within the layout XML?
Specifically, I have 2 layouts that each have a ListView. I've also implemented a custom layout for the list items.
The custom list item layout has 3 buttons, however, for one of the activities, one of the buttons isn't relevant and must be removed/hidden.
Is it possible to accomplish this in the layout XML? I'd really rather not create another custom list item layout just to remove one button for one activity.
Thanks in advance.
Put in activity a button.setVisibility(View.GONE);

How to have two layout xml files in a single activity in android

I am developing application in android.What I want is ,my activity should represent two xml layouts files.concept is like,
->when the activity is started it should show one layout(screen)
->when I click on the button exist on the first layout, it should show 2nd layout in the bottom of the screen,keeping first layout visible.
Have both the layout in a single XML. Keep the visibility of the the second layout to secondLayoutObject.setVisibility(View.GONE) initially and then on the click of the button change its visibility to secondLayoutObject.setVisibility(View.Visible).
On method to call two xml files in on activity is by using layoutmanager and assign the screen ratio for both xml files. Use relative layout in both xml. Small code snippet is
RelativeLayout layleft = (RelativeLayout)inf.inflate(R.layout.firstxml,null);
RelativeLayout layright = (RelativeLayout)inf.inflate(R.layout.secondxml,null);
for detail info Layout Reuse help
For this you have to use the concept of visibility. Initially set visibility of second layout as GONE and when you press button set Its visibility True.
you can try use the bellow example:
https://github.com/AdilSoomro/Iphone-Tab-in-Android
this source code to change layout like button click to load another layout!

Android: How can I create a layout within a layout ?

In my app I want to have a button that if the user clicks it
than a new layout is opened within the current (acually the main) layout.
the new layout should not fill all of the screen and parts of the previous layout
should be grayed out.
Any ideas on how to do this ?
You can show a hidden layout within your button's onClick event by calling
view.setVisibility(View.VISIBLE)
You can also fade out view elements or whole views with
view.setAlpha(75);
view.setBackgroundColor(Color.GRAY);
Note that "view" in the first example is your layout element.. LinearLayout, RelativeLayout, etc. and in the 2nd example, "view" is the element(s) you're trying to gray out.
Follow the answer of SBerg413. And for more information. you can take the relativelayout for the part that you want to hide and display on the button click.
And as like SBerg413 answer. you can hide the respective layout and show the layout you want to display.
Hope it will help you.
Thanks.
you can use a ViewFlipper to achieve what you want, position the viewflipper where the child views should fit (part of the screen you say)..
Inflate the rest of the "child" layouts from other xml, add them to the flipper and switch between them when you want...

Nested text view in android,with dynamic content

I want to display a recursive or nested text view at depth of 3 in Android.The text to be displayed is, dynamic coming from web service.
for example:
If I Click on Help(Level 1)
it'll show topics under Help
If I Click on Help_Topic_1(Level 2)
it'll show questions under Help_Topic_1
If I click on this question, say HT_Question_1(Level 3)
it'll show Answer of that question(Level 3)
how to accomplish with this? please guide me.
You should use ExpandableListView. Reference http://developer.android.com/reference/android/widget/ExpandableListView.html
You can call expandGroup and collapseGroup methods for expanding and collapsing on clicks.
the simplest way to do this is to have a nested layout structure. Your root view will contain the button to show level 1 and a child layout and initially be visible. The children's layout visibility will initially be set to "GONE". In the onclick listener for each button you change the visibility of the layout below it to view to "VISIBLE".
This of course is a very simple way of doing it. If you require to have open and close animations you'll need to use a more complex method.

Categories

Resources