AutoCompleteTextView items' text not visible - java

I'm loading an AutoCompleteTextView with lots of items but none of them is shown/visible in the popup.
P.s.: If I click somewhere in that empty white view, the text appears in the AutoCompleteTextView (it's white text)
resource.xml
<AutoCompleteTextView
android:id="#+id/reg_city"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/input_register_bg"
android:hint="Città"
android:padding="10dp"
android:singleLine="true"
android:textColor="#color/input_register"
android:textColorHint="#color/input_register_hint" />
activity.java
ArrayAdapter<String> citta_adapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_list_item_1, list_cities);
in_city.setAdapter(citta_adapter);

Most probably the suggestions are white-on-white, which is why you're not seeing them, but pressing on a suggestion works.
See this for a list of possible solutions: AutoCompleteTextview Color set white by default

Related

Spinner is baraly visible

I have a problem, when I run my Android App on the emulator, I can fine see my Spinner, but when I run it on my phone it's hard to see the spinner.
I tried to cut out some color, to see if there is anything in the spinner, but no :( It just show a number but I can fine press the number and it shows the content of my Spinner , but I want to see the background of my Spinner
MainActivity.java
final String[] plHand = getResources().getStringArray(R.array.yourHand_array);
final String[] dlHand = getResources().getStringArray(R.array.dealerHand_array);
final Spinner sp1 = (Spinner) findViewById(R.id.spinPlayer);
final Spinner sp2 = (Spinner) findViewById(R.id.spinDealer);
final ArrayAdapter<String> ar1 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, plHand);
final ArrayAdapter<String> ar2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, dlHand);
sp1.setAdapter(ar1);
sp2.setAdapter(ar2);
My XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.black.jack.rechner.MainActivity"
android:background="#drawable/table"
tools:ignore="MergeRootFrame" >
<Spinner
android:id="#+id/spinPlayer"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:textColor="#FFFF00"
android:layout_marginTop="20dp" />
<Spinner
android:id="#+id/spinDealer"
android:layout_width="110dp"
android:textColor = "#000000"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="20dp" />
I tried to change the Textcolor but with no luck, hope you can spot the tiny mistake I made.(Don't worry about the design it's a beta :P)
The styling of components like that can vary from device to device. So, if you want it to stay the same on all devices you can specify a background for it. Something like;
<Spinner
android:id="#+id/spinPlayer"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#FFFFFF"
android:layout_marginTop="20dp" />
The example above will make the background entirely white. If you want a more robust background like the one you linked in some comments, then you'll need to create an image file, store it in your drawable folder and refer to it like so;
android:background="#drawable\your_spinner_background_image"
Seems you need to style it correctly. Now it uses the phone theme whats probably not matching the rest of the color scheme in your application. For a guide styling the spinner see the following website:
http://adanware.blogspot.in/2012/03/android-custom-spinner-with-custom.html

android autocomplete renders as blank list in portrait mode

I have a normal autocomplete:
<AutoCompleteTextView
android:id="#+id/autocomplete_names"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/namesauto_prompt"
android:imeOptions="actionDone"
android:completionThreshold="2"/>
...
AutoCompleteTextView nameinp = (AutoCompleteTextView) findViewById(R.id.autocomplete_names);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, names);
nameinp.setAdapter(adapter);
I won't bother showing the names list, because it which works fine on my tablet running ICS, both in landscape and portrait modes. In landscape on my phone (Gingerbread) it does OK - the names appear the same way that autosuggest for texting does. But in portrait mode it just renders a blank listview beneath the autocomplete input. Any ideas why?
UPDATE
So, having played around with it, I notice that my list is there, it's just that it's white text on a white background (kind of hard to read). I can set my
android:popupBackground
to whatever color I like (dark gray is a contender at the moment) but I can't see a way to change the text color for the popup (or dropdown as it were), nor do I really understand why it's white in the first place...
I don't know the problem of this issue, because even I faced this issue with AutoCompleteTextView. I found a workaround for this.
What you can do is set a custom xml in the ArrayAdapter that will have the TextView color set to black.
The custom TextView file my_custom_textview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/dropDownItemStyle"
android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee" />
And set this xml in your ArrayAdapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.my_custom_textview, names);
nameinp.setAdapter(adapter);
Hope this helps you..

How to programmatically hide android some, but not all, view items in an XML output?

I'm trying to program a disc golf scoring app on Eclipse for my android phone. I'd like to set it up for up to 6 players, but mostly 2 people will use it for a game. The data is being stored in a sqlite DB, and I am using a SimpleCursorAdapter to populate the data for holes that have already been scored. here is that code:
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{DiscGolfDbAdapter.KEY_HOLE,
DiscGolfDbAdapter.KEY_PAR,
DiscGolfDbAdapter.KEY_TOM_HOLE,
DiscGolfDbAdapter.KEY_TOM_GAME,
DiscGolfDbAdapter.KEY_CRAIG_HOLE,
DiscGolfDbAdapter.KEY_CRAIG_GAME,
DiscGolfDbAdapter.KEY_TOMS_POSITION,
DiscGolfDbAdapter.KEY_SKIP_PLAYER
};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.schole, R.id.scpar, R.id.scth, R.id.sctg, R.id.scch, R.id.sccg, R.id.sctp,
R.id.skip};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.hole_info, notesCursor, from, to);
setListAdapter(notes);
}
From searching the internet I've found what I think are two posibilities that SHOULD work, but do not.
First I've tried the XML Attribute: android.visibility. It looks like this in the PORTION of the view that I am trying to "test" hide:
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android.visibility="GONE">
<TextView android:id="#+id/scch"
android:layout_width="45dip"
android:gravity="right"
android:textSize="25sp"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/sccg"
android:layout_width="45dip"
android:gravity="right"
android:textSize="25sp"
android:layout_height="wrap_content"/>
</LinearLayout>
I have tried it with "GONE", "Gone" and "gone". NONE of them work in the eclipse emulator OR on my actual phone. So, there is no point in trying to parameterize this attribute.
Next I've tried setting the XML attribute for android:layout_height to "0dip". This indeed works in the emulator and on my phone WHEN IT IS HARDCODED.
Then I moved to the next logical step (as I see it), storing a parameter in the DB so that I can "show" or "not show" the item DEPENDING on conditions within the record. So, I've stored a field in the DB with two values "0dip" and "wrap_content". I pass these to the layout as shown in the java above as R.id.skip. I've also added these to the output just to audit that they are really there. Here is that XML:
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="#+id/skip">
<TextView android:id="#+id/scch"
android:layout_width="45dip"
android:gravity="right"
android:textSize="25sp"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/sccg"
android:layout_width="45dip"
android:gravity="right"
android:textSize="25sp"
android:layout_height="wrap_content"/>
</LinearLayout>
<TextView android:id="#+id/skip"
android:gravity="center"
android:layout_width="315dip"
android:textSize="10sp"
android:layout_height="wrap_content"/>
In the above test, both via the Eclipse emulator and my android phone, the last TextView confirms that the DB contains either "0dip" or "wrap_content", BUT the LinearLayout with:
android:layout_height="#+id/skip">
behaves as if it were "0dip" ALL of the TIME. In other words, I cannot PROGRAMMATICALLY" affect the XML attribute for android:layout_height.
If there is a better/more standard way of accomplishing what I am trying to do, please share - BUT BE CLEAR. I am new, so CODE EXAMPLES wwill work best for me.
May 29th - It seems to me (based on testing) that you cannot alter layout attributes for the layout specified in this code:
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
R.layout.hole_info,
notesCursor, from, to);
setListAdapter(notes);
Anything I try leads to some error ort another. So, I've seen examples of custom list adapters where these attributes are altered, so I'm trying to convert to a custom list adapter.
Why not do it in code?
LinearLayout ll = (LinearLayout)findViewById(R.id.your_layout_id);
ll.setVisibility(View.GONE);
Your XML layout code
android.visibility="GONE"
should be
android:visibility="GONE"
Change visible of a LinearLayout like Gabriel Neguţ say:
LinearLayout ll =
(LinearLayout)findViewById(R.id.your_layout_id);
ll.setVisibility(View.GONE);
or change height of LinearLayout:
LinearLayout ll = (LinearLayout)findViewById(R.id.your_layout_id);
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams();
lp.height = 0; // or lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;
ll.setLayoutParams(lp);
What about this guy's solution http://enjoyandroid.wordpress.com/2012/03/12/customizing-simple-cursor-adapter/
Kind of worked for me.

Android Listview Horizontal

My xml (lvlayout.xml) layout for a listview is currently like this:
<TextView
android:id="#+id/busnum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dip"
android:gravity="center_horizontal" />
<TextView
android:id="#+id/servdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dip"
android:textColor="#23cf34" />
I populate the listview via a simplecursor adapter like this:
dueAdapter = new SimpleCursorAdapter(main.this, R.layout.lvlayout,
dueBusesCursor, columnsdue, to);
dueListView = (ListView) findViewById(R.id.ListView01);
dueListView.setAdapter(dueAdapter);
How can I make the listviews horizontal so that the user scrolls sideways ? thanks in advance.
ListView does not support the horizontal mode. The closest thing to a horizontal ListView is Gallery.
you can use ViewPager :
http://developer.android.com/reference/android/support/v4/view/ViewPager.html

ListView where each item is an ImageView with a radiobox and one item can be selected at a time?

I'm tearing my hair out over this. I would like a ListView where each item in the list is an ImageView. I want each item to have a radio button next to it and only one item can be selected at a time (i.e. single choice mode). This code works fine for creating a list of text box with radio buttons:
ListView listView = ...
String [] value = {"test1","test2"};
listView.setAdapter(
new ArrayAdapter<String>(
this, android.R.layout.simple_list_item_single_choice,value
));
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
For my ImageView items, I implemented by own ArrayAdapter. In the getView method of my ArrayAdapter object, I load the follow xml file for each list row:
e.g.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="center"
>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="6dip"
android:paddingRight="6dip"
/>
<ImageView android:id="#+id/preview"
android:layout_width="75dip" android:layout_height="100dip"
android:scaleType="fitCenter"
android:enabled="true"
android:focusable="false"
/>
</RelativeLayout>
I copied the CheckedTextView item from the simple_list_item_single_choice.xml file used in the previous example. I assume that ListView must look for an item with id "text1" to use for displaying the selection status (I'm just guessing here as I cannot work out where the radio buttons are meant to come from). If I don't include the CheckedTextView item, I don't see any radio buttons at all.
When I use my custom adapter with the above xml file, I can see the radio buttons but selecting them does nothing. In addition, I've implemented the selection listener for the list view and this do not fire when I click items. What am I doing wrong?

Categories