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.
Related
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 want to make a pull-to-refresh listview, and i use the android.support.v4.widget.SwipeRefreshLayout,bus also i want to the item of listview can swipe left or right. like the gmail in android 5.0. who can help me? sample or code. or tell me how to do it. really really thx!
You may refer to this sample application Swipe_list_item_To_Delete You may use ListView to list your data items which are got from the db or server. Then modify the getSwipeItem() method in the MainActivity of the example, as follows, if you are deleting the item from the list onSwipe()
#Override
public void getSwipeItem(boolean isRight, int position) {
[List_Of_Items].remove(position);
[Your_Adapter].notifyDataSetChanged();
}
And refer following Github sample Pull-to_RefreshListView for pull to refresh list view
I'm developing an application that shows stock market information. In my application I use listactivity and my own adapter is being used.
The listView used to show the stocks is working fine and is updated with correct data. The only problem is, although I use
adapter.notifyDataSetChanged();
the list isn't updated until scrolling and items subjected to change, are scrolled out from the screen. When they are scrolled in, they appear with new data.
I need to change the data as soon as I notify the adapter.
I have face same problem
but finally got solution
And its solution is
listView.invalidateViews();
I think for that you have to take the help of the Lazy ListView or Lazy Loader:
Check out the below link :
Lazy load of images in ListView
It will help you.
Are you calling notifyDataSetChanged in UI thread? If not: you can do the following:
runOnUiThread(new Runnable() {
public void run() {
adapter.notifyDataSetChanged();
}
});
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