Spinner works in 2.3 but not 3.2 - android

I have been successfully running an app under android 2.2 (api8) using spinners with OnItemSelectedListeners. It was built with tarketSdkVersion = 8 and minSdkVersion = 8. I am now trying to run it on a 3.2 device, but the spinners can not be selected. They do populate with the default array value however, so the adapter appears to be working. Clicking on the spinners results in no reaction. I tried building with tarketSdkVersion = 13 and minSdkVersion = 13, but the spinners are still dead. I am using slightly customized spinner versions to achieve "wrap_content" in a multiline_spinner_dropdown_item.xml file. Is there a compatibility issue with spinners since 2.2?

I tried the .setEnabled(true) but it didn't work. In frustration, I started to remove sections of code from main.java and layout.xml until a single spinner was left and working. As I added the code and controls back, I found that a ScrollView nestled inside a TabHost/LinearLayout/TabWidget/FrameLayout prevented the Spinners from responding. By removing the Scrollview, the Spinners worked in 3.2. For some reason the Scrollview worked in 2.2, but not 3.2.

I had the same problem, I used the spinner in 2.2 ,it was working but the same do not work in 3.2, The problem was with the default theme of 3.2, its holo. because of that the spinner is not shown properly,
Just create a theme in values/style, and apply it to your activity in android.manifest file.

Are you by any chance changing the visibility of the spinner?
I had a similar problem, and it was necessary to call setAdapter() every time the spinner was re-shown, otherwise it became immune to clicks.
You can see the change I made to my project that fixed this problem at https://github.com/nikclayton/android-squeezer/commit/7a148edf5f1b3eaca7718161de18254970290ce0.

Perhaps some visibility issues ?
Are you stacking the ScrollView on top of the area where the spinners' items show up ?
Try to use different states for the spinners by changing their icon or color for example and see if they get the click event. If they do, then it is probably something related with visibility. If they don't, it might something else.
Some code sample could help :)

Have you tried setting the spinner as enabled?
spinner.setEnabled(true);
Although it would be weird that it was disabled on default. Your symptoms do describe a disabled spinner though

Oddly, I tried another app of my that works great on 2.2. When I installed it on a 3.1 tablet or emulator, the onClick events won't fire. No spinners this time, but the listeners don't work either! Here's some of the code:
//In onCreate:
//setup listeners
rbSlab = (RadioButton)findViewById(R.id.rbSlab);
rbBeam = (RadioButton)findViewById(R.id.rbBeam);
rbSlab.setOnClickListener(radio_listener);
rbBeam.setOnClickListener(radio_listener);
etFpc.setOnEditorActionListener(this);
etFy.setOnEditorActionListener(this);
etBw.setOnEditorActionListener(this);
etDp.setOnEditorActionListener(this);
etMu.setOnEditorActionListener(this);
...
}//end onCreate
//In Main body of app:
//for radio buttons
private OnClickListener radio_listener = new View.OnClickListener()
{ //#Override
public void onClick(View v) {
DoCalcs();
}//onClick
};
//for edittext
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{ if ((actionId == EditorInfo.IME_ACTION_DONE) || //if DONE button pushed
((event.getAction()==KeyEvent.ACTION_DOWN) && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) //if ENTER button pushed
{
//do calcs
return(true);
}
else return(false);
}
I've built this with target API 8 and min API 8, and also with target API 14, min 8, and when installed on a API 8 the listeners work fine, but not with API 14!

I had a similar problem. It's because of the default theme of Android 3.2 and above versions.
The simpler solution is to use a custom spinner, or to make any background colour or picture for the same, like:
android:background="#drawable/spinner"
This link will help you for custom spinner.

Related

Android scrolling makes whole screen blue

I have not been able to replicate this, but is anyone aware of what might cause the entire screen on an Android device to go light blue? It seems related to selecting a radio buttons and then scrolling. It happens on Nexus 5x with Android 8.
Here is what it looks like:
I have only heard of one other instance of this occurring. Could it be device specific? Strangely enough, once it happens it seem to stay this way, though the user says it is somewhat intermittent.
Update:
This only seems to happen on Android 8, if that helps anyone...
So, I eventually found the offending code. I verified this is only happening on Android 8 devices, maybe only Samsung? The offending code was:
mFormScrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
mFormScrollView.setFocusable(true);
mFormScrollView.setFocusableInTouchMode(true);
// Hide the keyboard when moving the screen up or down. This should only
// be an issue when
// on a text edit field. Also disable focus jump using
// "requestFocusFromTouch"
mFormScrollView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_DOWN) {
Utilities.hideKeyBoard(FormActivity.this, view);
}
// Keeps screen from jumping to nearest EditText
// view.requestFocusFromTouch();
return false;
}
});
The offending line is commented out - the view.requestFocusFromTouch() method, which was meant to keep the screen from auto jumping to the next text field when the keyboard was hidden and focus lost. On Android 8 this is not happening, but I need to verify with older versions.

Activity Background change dynamic

I have just started developing an android weather app and I was wondering how to change activity background automatically. For example, in daytime it should show day time or in the night it should show night photos.
This is the app of Sony which has a feature (mentioned above)
Check the screenshots.
Okay Credit goes to SteD;so for you check this(beginner's guide)
Follow this
//set an ID for Relative Layout in content_main.xml(Android Studio)
RelativeLayout rlayout=(RelativeLayout)findViewById(R.id.rlayout);
if(something){Drawable drawble=getResource().getDrawable(R.drawable.your_image);rlayout.setBackgroundDrawable(drawable);}
//If it works,destroy the upvote
The only automatic way is the newly released (Day/Night theme for android app)
For finer control you check the condition yourself and call the normal Java methods, like this:
if(something) {
getWindow()
.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.image));
}
of if you don't care about the newly introduced context themed styling, you just call the deprecated method (which will keep working without issues for all the foreseeable future)
if(something) {
getWindow()
.setBackgroundDrawable(
getResources().getDrawable(R.drawable.image));
}

Selecting text on TextView (android 2.2)

How to implement selecting text capability on Android 2.2? I searched Google but can't find a solution.
This is the only way I've found (from google) to support it for android 1.6+, it works but it's not ideal, I think in stock android you can't hold down a webview to highlight until v2.3, but I may be mistaken..
By the way this is for a webview, it might also work on textview, but I haven't tried it
(Note: this is currently what my shipped app is using, so it works with all the phones I've had it tested on, but the only reason I found this question was because I was searching and hoping that someone had come up with a better way by now)
I've just got a menu item called "Select text" which calls the function "selectnCopy()"
#Override
public boolean onOptionsItemSelected(MenuItem item) {
//..
switch (item.getItemId()) {
case R.id.menu_select:
selectnCopy();
return true;
//..
}
}
Which looks like this:
public void selectnCopy() {
Toast.makeText(WebClass.this,getString(R.string.select_help),Toast.LENGTH_SHORT).show();
try {
KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(wv);
} catch (Exception e) {
throw new AssertionError(e);
}
}
Notice I've put the select_help string there as a toast, that's just because it's not immediately clear to the user how it's supposed to work
<string name="select_help">Touch and drag to copy text.</string>
The Link #Stefan Hållén provided only worked after API Level 11.
And Android 2.2 is API Lv.8, that's the reason why you cannot get a resource identifier.
Have you set the text to be selectable? like this:
android:textIsSelectable="false" //OR true
See the Documentation for further reference.
After a long and time consuming search, I can't find a component that can select text in textview for android API level <=11. I have written this component that may be of help to you :
new Selectable TextView in android 3 (API <=11) component
An interesting workaround:
You could try displaying your text in a webview.
You just have to write the HTML tags and all of that into your string to display, and it should be selectable using the WebKit browser.
This should be fairly lightweight and transparent to the user, and I think it would solve your problem.
Let me know if you need a code example, it should be fairly simple. Just check out the WebView docs on http://developer.android.com/resources/tutorials/views/hello-webview.html
Best of luck!

Android OnLongClickListener strange / unreliable behaviour

I'm currently fighting against the OnLongClickListener on Android Api Lvl 8.
Take this code:
this.webView.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
System.out.println("long click");
return true;
}
});
It works perfectly. I can press anywhere on the WebView and the event triggers every time.
Now take a look at this one:
this.webView.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
final EditText editText = getUrlTextField();
switch (editText.getVisibility()) {
case View.VISIBLE:
editText.setVisibility(View.GONE);
return true;
case View.GONE:
editText.setVisibility(View.VISIBLE);
return true;
default:
return false;
}
}
});
Assuming the URL EditText components is currently visible, it gets gone from the display and should be shown again when another long click event is triggered.
But if you run this, the event just works once (!) when one performs a long click on any position on the WebView. To make things complicated, the long click works again when it is performed on a link on the website...
Can anyone explain if it is a bug in the sdk and/or if there is a mistake in my thinking how the OnLongClickListener is working?!? :/
EDIT:
I've run now several different scenarios on a Nexus One and come to following conclussion: Changing the layout on runtime more or less kills the OnLongClickListener... I haven't found a way to get it work reliably at all...
I would really appreciate if anyone could give me a hint... I'm at my wits end :(
Personnally, I ended up by re-setting the listener after each relayout.
I've run into this issue as well. It seems that if the view layout changes in a way that child view bounds need to be modified (i.e. TextView is wrap_content width and you set its text to something longer/shorter than it was before), views in the hierarchy will have their onStartTemporaryDetach method called (most likely due to a layout pass, although I haven't dug deep enough to find out for sure). If you look at the source for View that onStartTemporaryDetach ultimately unsets the pressed state of the view.
Changing the views in your layout that will be updated periodically to have bounds that will not change regardless of the value you set, will fix the issue. Although, that is still not awesome.

Android 2.1 fling gesture captured on textview but still a contextmenu opens

The following problem seems unique to 2.1, happens both on an emulator and on a nexus. The same example works fine on other platforms I've tested (1.5, 1.6 and 2.0 emulators).
I've added created gestureListener as described in this post.
The difference is that I've added the listener on a TextView which also has a contextMenu registered, i.e. sth like the following:
onCreate(...) {
...
// Layout contains a large TextView on which I want to add a context menu
tv = findViewById(R.id.text_view);
tv.registerForContextMenu(this);
// create the gestureListener according above mentioned post.
gestureListener = ...
// set the listener on the text-view
tv.setOnTouchListener(gestureListener);
...
}
When testing it, the correct gesture is recognized alright, but every other time it also causes the context menu to be opened.
As the same example is working on non 2.1 platforms, I've got a feeling it is not my code that is the problem...
Thankful for any suggestions.
Update:
Seems that the return value is flipped somewhere. If I let onFling() return the "wrong" value, i.e. true when the event is skipped and false when it was consumed, it works correctly in 2.1. But of course, that doesn't work on the other platforms. Seems like its time for an ugly workaround...
Thanks for the link steelbytes. I implemented the cancel-and-return-false solution in the last comment (Dec 27, 2010) but just for my onFling event and it appears to work on 1.6 as well as 2.x devices.

Categories

Resources