HI,
Iam writing GridView by using BaseAdapter with 2 columns.Each column with One Image and Text.It works smoothly.I had given focus by using below code in onConfig...
public void onConfigurationChanged(Configuration newConfig) {
gridview.requestFocusFromTouch();
gridview.setSelection(0);
}
It works when my view configuration changes.But Same doesn't work in onCreate() method.
I used below all methods in onCreate() but my view doesn;t get focus.How to give focus for the first image when running my application.I want focus on first image when view inflates on the device.Please give me guidance?
gridview.requestFocus();
gridview.requestFocusFromTouch();
gridview.setSelected(true);
gridview.setSelection(0);
gridview.setFocusable(true);
gridview.setFocusableInTouchMode(true);
gridview.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
Regards,
Rajendar Are
This worked for me.
mGridView.setSelection(iPos-1);
mGridView.requestFocusFromTouch();
mGridView.setSelection(iPos-1);
Unknown why have to do it twice:
Maybe, you can do like this:
"sleep" little time
Thread.sleep(1);
gridview.requestFocusFromTouch();
gridview.setSelection(position);
I managed to do this by just calling mGridView.setSelected(true); in onResume()
In this way my 1st element has got the selection.
Now I'm looking for ways how to set selection for random element
Related
Hi I'm implementing click listeners in the following way but after some time the methods and variables inside the listener's closure get the wrong values or something. Let me explain the implementation of the listener a little better a for loop creates the listener for a set of image views then later in the program the for loop is called a second time and it resets the listener methods and variables to different values. Everything works great for about 30 minutes but then for some reason, the listener's methods and variables start having the wrong values. Has anybody ever heard of this behavior or can tell me where I've gone wrong with the code? Keep in mind that the listener I'm about to paste here is just a small piece of a 1014 line class. I'm hoping somebody can spot How I'm implementing the listener wrongly and can give me some advice on how to "reset" the listener so that it's variables and values stay over time. Hopefully you can read the code without putting it in an editor but feel free to copy it for readability's sake Here is the code for the image view listener with comments.
//image views are held in an array
//set an image view in its imageview container
imgArr0[slotId1].invalidate()
imgArr0[slotId1].setImageDrawable(null)
//drw is not defined in this example
imgArr0[slotId1].setImageDrawable(drw)
/*if video or image id is set to image then set a listener for the image
*/
/*slotId1 is not defined in this example but it is simply a counter to iterate over the ImageView array
*/
if (videoOrImageId0[slotId1] == "image") {
//null any listeners that might be attached to the image view
imgArr0[slotId1].setOnClickListener(null)
//set or reset the listener
imgArr0[slotId1].setOnClickListener() {
`enter code here`//if the current config is portrait then set a new image image
if (currentConfig0 == "portrait0") {
act0.lrgImage0.invalidate()
act0.lrgImage0.setImageDrawable(null)
/*drw is not defined in this example but works fine in the production script
*/
act0.lrgImage0.setImageDrawable(drw)
}
--calmchess
ccc tv application with problem.
(https://i.stack.imgur.com/PjdbN.jpg)![enter image description here](https://i.stack.imgur.com/FaMnc.
I was able to partially solve this question by destroying all the image views and their associated click listeners then rebuilding those... However I don't consider this issue completely solved so if anybody can provide a better solution I'd love to hear it because rebuilding the images every few minutes has to be using a lot of unnecessary hardware resources.
--calmchess
greeting,I am developing one app where i am implementing load more on RecyclerView view by using interface.
But the problem is that it work fine for first time and after that mOnLoadMoreListener will be null,i dont know why mOnLoadMoreListener will null.
so it will not load next element
This is my code and my listener is as follows
OnLoadMoreListener.java
public interface OnLoadMoreListener {
void onLoadMore();
}
The main problem is that at first time it load the data well. and when i scroll the list down and when i reach at last item it will load next data at first time but after that it doesnt work...
I checked mOnLoadMoreListener it become null.
So please give a solution. i am getting irritated because of it.
Please help me.Solve this problem because it is important for me.i searched on internet but i didnt get any help
Thanks in advance
As I see, first time you create adapter = new DataAdapter(); in onCreate() method and set adapter.setOnLoadMoreListener(new OnLoadMoreListener()). But later in getProducts() method you recreate adapter (check JsonArrayRequest->onResponse) and lose OnLoadMoreListener. So this is the problem I suppose.
I'm having a weird issue with AutoCompleteTextView.
I have a AutoCompleteTextView that shows suggestions of cities when typing in it.
The list of cities is retrieved from a remote server via JSON. When I use the soft keyboard or the Mic Button on the soft keyboard, the suggestions work fine. AutoCompleteTextView does show the suggested cities.
But, I have a problem when I try to set the text using myAutoCompleteTextView.setText("Chi") , the auto complete does not show..
I have also tried myAutoCompleteTextView.append("Chi") but still no luck..
The adapter is there, its just that the suggestions don't show.
Any tips?
Thanks.
Yes you are right there is a bug in AutocompleteTextview to show default suggestion using setText(""); method.
But you can achieve this by adding some more lines of code as below.
autoText.postDelayed(new Runnable() {
#Override
public void run() {
autoText.showDropDown();
}
},500);
autoText.setText("chi");
autoText.setSelection(autoText.getText().length());
It is due to filtering,
No Need to any extra code for manage it, I found it in very easy and working way.
Google Dev. Reference link
autoText.setText("Default Value here",false)
autoText.setSelection(autoText.text.count()) // kotlin
as per documentation second parameter you can pass for filtering.
boolean: If false, no filtering will be performed as a result of this call.
Biraj Zalavadia's answer work, but you must write to "settext" in Runnable.
Like this:
mACTextViewEmail.postDelayed(new Runnable() {
#Override
public void run() {
mACTextViewEmail.showDropDown();
mACTextViewEmail.setText("My text is here");
mACTextViewEmail.setSelection(mACTextViewEmail.getText().length());
}
},500);
I searched for it and just found this solution that worked so well
Look at this issue
fun AutoCompleteTextView.showDropdown(adapter: ArrayAdapter<String>?) {
if(!TextUtils.isEmpty(this.text.toString())){
adapter?.filter?.filter(null)
}
}
In kotlin language, you can use this extension function.
I have done with Gallery in my project. It is working very fine, i was trying to use setSelection method of gallery so that at the start up i can define which item to be selected rather than always selecting first item.
I have tried to use setSelection(5) so that selection goes to 5th child but the gallery always select the first item. Is there any clue to integrated it perfectly.
Please try this:
your_gallery_view.post(new Runnable() {
#Override
public void run() {
your_gallery_view.setSelection(5);
}
});
Hope this helps.
I got the solution. We need to put the set selection method after setAdapter method. I was doi ng it before setting the updater. It is working fine. Thanks to all who tried to help me out.
I have a ListView that potentially can have hundreds of entries. When a selection is made I've been using a smoothScrollToPosition, thusly:
if (lv != null) { //Are we created yet?
lv.post(new Runnable() {
public void run() {
lv.smoothScrollToPosition(k);
}
});
}
but my users have told me they don't like the scrolling animation and would prefer to just instantly go there. So I replaced my smooth scroll with
lv.setSelection(k);
... and now it does nothing at all. FWIW this is all happening right after a notifyDatasetChanged
In searching for a solution I came across this discussion on http://code.google.com/p/android/issues/detail?id=6741 which implies this is a known problem. Is there a workaround or am I just doing this wrong?
Thanks in advance.
The documentation of setSelection says that it only scrolls to the selected position when the ListView is in touch mode. Maybe ListView is no more in touch mode once the data set has changed or maybe setSelection is simply forgotten for the next UI update cycle.
I guess you could try a workaround by calling setSelection with a delay. You could use the postDelayed method with a delay of 100 milliseconds for example. Or you could extend ListView and override layoutChildren or something related that probably gets called when the data set changes in order to re-calculate the list view item measurements. At that point it should be safe to call setSelection and you don't need to rely on guesstimating a delay.