Achive Scroll without scrollView - android

Yesterday I attain one interview where he asked one question :
if in a layout one banner is there and bottom of this banner ListView is there. without using scroll view how you will scroll the screen.
Edited:
Suppose In the xml file Linear layoutis there. Then add banner into the linear layout(in ImageView), then ListView is there. Now scroll the screen. How it will scroll?

I think you can do the same with the help of the getView() method of Custom adapter.
like the below:
public View getView(int position, View convertView, ViewGroup parent){
View view= convertView;
if(view==null){
if(position==0){
view=inflater.inflate(R.layout.imageViewLayout, null);
}else{
view=inflater.inflate(R.layout.otherLayoutForListItem, null);
}
}else{
}
}
I think this can help you
but if you don't want to include in this way than u have to handle some other scroll option of the list View

Related

How to make expandable recycler view like imgur comment section

I want to make expandable recycler view with dynamic no of item. I need same recycler view as imagur comment section for each image. How to add that dynamic no of childern view in row of recyclerview.
Thank you
I asked similar question but no one answer so i searched and find a way.
you can define a layout for your view and inflate it programmatically.
it's not against preferences in Android. So inflate your layout using LayoutInflater :
LayoutInflater inflater = LayoutInflater.from(context);
View inflatedLayout= inflater.inflate(R.layout.yourLayout, null, false);
yourParentView.addView(inflatedLayout);
"yourParentView" is the Relative or Linear Layout. don't forget to add this LayoutInflater in your "onBindViewHolder". hope this work.

How to get a ListView's child view at specific index

I need to dynamically change the background color of a child view of a ListView at a specific index. So I need to get the view first before applying the background.
I have tried the following.
getViewAt(int index) - this is not applicable to ListView.
getChildAt(int index) - this gives runtime NPE error
A Google search returns irrelevant results.
Please help me out. Thank you.
I figured out how to do this.
I really think that one should not have to post code and logcat for a question that is similar to "How to set background image".
Anyway my answer is, in short, set position as tag for every child in the listview through your adapter's getView() and then get any child using findViewWithTag(Object tag).
#Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = (LinearLayout)inflater.inflate(R.layout.some_layout, parent, false); .
convertView.setTag(String.valueOf(position));
}
And whenever you need to get a specific child.
View v = mylistview.findViewWithTag(String.valueOf(index));
To change background color.
v.setBackgroundResource(R.color.some_color);
Use getChildAt(index) from ViewGroup to get View.

Custom view loses background resource when not in view

So, I'm adding an ad from either AdMob or MMAds, OR I have the MMAds Interstitial ad come up, and on exit, OR I touch one of the list items, starting a new activity, then at the end of the activity, this happens:
http://i.imgur.com/Zq7vvkQ.png
The top item doesn't have a background resource being drawn, the bottom is similar to this. This happens sometimes to the ones in the middle (With the ads, they ALL go away).
I was wondering why this happens and how to prevent it... The most I could find on other questions is one on using the following code on the ListView:
android:cacheColorHint="#00000000"
Or
android:scrollingCache="false"
The background resource is being drawin in the custom ListAdapter's getView(int, View, ViewGroup) method.
Any help is appreciated,
Justin W.
To verify your problem try to run hierarchyviewer, analize your views tree and try to find potential solution. Have you used Hierarchy Viewer?
So, I had a bit of code:
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
item = inflater.inflate(R.layout.griddler_menu_choice_item, parent, false);
} else {
item = convertView;
}
return item;
}
Basically this was to keep it more efficient so it didn't have to keep creating Views as it's costly, but this somehow effected the end result... So now it works =).
Forgot to add in how to fix this... remove the else part and the if in general, just leave the line of code:
item = inflater.inflate(R.layout.griddler_menu_choice_item, parent, false);
That fixed it for me.

Android HorizontalScrolling laggy

I have a HorzontalScrollView with a LinearLayout inside. During Runtime I can add more LinearLayouts to the LinearLayout.
Now I have the problem that the Scrollview only scrolls a little bit and not smooth with one finger slide!
Does anyone have a solution for this problem?
HorizontalScrollView doesn't use an adapter that manages the list's memory, therefore it can't handle heavy (images, custom views, etc) lists.
You can use this Horizontal ListView http://www.dev-smart.com/archives/34 but make sure you don't write the on list item click method inside the getView, it will make the list scroll slow. Other than that, that's a great resource for a smooth horizontal list view.
You can also explore the Android view pager, which is also supported on lower Android versions using the compatibility pack: http://developer.android.com/sdk/compatibility-library.html
Edit - something like that in the adapter that inflates the XML you want (the linearLayout) and then populates every view with the relevant data.
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_friends_list_item, null);
}
ImageView status = (ImageView)convertView.findViewById(R.id.status);
ImageView image = (ImageView)convertView.findViewById(R.id.image);
ImageView imageBorder = (ImageView)convertView.findViewById(R.id.image_border);
TextView title = (TextView)convertView.findViewById(R.id.title);
}
The problem was my parent Viewflow because it has stolen the swipe event! The HorizontalListView is too buggy for me! (Problems with size attributes)
However,thank you for your answer! ;)

Problem with custom views in Gallery (false focus received by component)

I'm having problem figuring out an issue with the Gallery component. I'm using a simple gallery with a custom Base Adapter. In the getView method, the view representing a gallery item is inflated:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
View promo = inflater.inflate(R.layout.view_promo, null);
ImageView promoBackground = (ImageView)promo.findViewById(R.id.promo_background);
promoBackground.setBackgroundResource(promoResources[position]);
convertView = promo;
}
return convertView;
}
The inflated view also has two simple button with a selector set as background. The problem is that when the gallery item is clicked/touched, the two buttons appear to receive focus, and the selector changes the background of the two buttons (even if the touch not occurs right over them). I've tried disabling both focus and click on all views that could receive the event, but no luck yet.
Any idea is welcomed!
Thanks
I just encountered this same issue, and found a solution here:
Gallery/AdapterView Child Drawable State

Categories

Resources