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
Related
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
EDIT: I've decided to go ahead and use a custom xml with a small change to get selection colors working. This doesn't completely solve my issue but I don't want to spend more time on it right now. Posting my current xml below in case it helps someone, and marking correct answer since it helped me pretty much achieve what i was going for in the first place. I ended up not needing to point to another xml if I use ?android:attr/selectableItemBackground
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/black"
android:background="?android:attr/selectableItemBackground" />
I've made a GridView wrapped in a Dialog with an ArrayAdapter.
I wanted to have some kind of border between the cells (1dp white or black). The only way I was capable of accomplishing this was to write a custom xml and use it instead of simple_list_item_1, which would be fine, except that seems to break the item highlighting on select and such, and I can't seem to match the default look of it with my custom xml.
The question: Could I possibly just locate and override the color scheme of the built in xml?
I made a small attempt in the code below, but unsurprisingly I get a null pointer exception. Most of the searching just turned up suggestions for a custom xml, but it seems odd to do all that for a quick font color and font background color change.
I'll throw in my xmls just in case.
Working with a minimum API 11 if it matters.
Thanks guys,
Mike
-Java Snippet-
...
public void gridDialog(View v) {
String[] letters = new String[] {
"A", "B", "C", "D", "E"};
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.grid_pop);
GridView mGrid = (GridView) dialog.findViewById(R.id.fret_grid);
TextView tv = (TextView) findViewById(android.R.id.text1);
tv.setTextColor(Color.WHITE);
tv.setBackgroundColor(Color.BLACK);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, letters);
//ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.my_item, letters);
mGrid.setAdapter(adapter);
mGrid.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(getApplicationContext(), ((TextView) v).getText(), Toast.LENGTH_SHORT).show();
// Do Stuff
dialog.dismiss();
}
});
dialog.show();
}
...
-my_item.xml-
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:gravity="center_vertical|center_horizontal"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/black" />
-grid_pop.xml-
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fret_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:columnWidth="55dp"
android:gravity="center"
android:horizontalSpacing="1dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp" >
</GridView>
Change to
android:textAppearance="?android:attr/textAppearanceListItemSmall"
and your item's will have the default selection behavior with the custom list item XML (a theory, haven't tested).
EDIT: Try this to make the list item light up when you tap it like the simple_list_item_1:
In the list item:
android:background="#drawable/clickable"
In drawable folder add this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#android:drawable/list_selector_background" />
</selector>
So I've googled, and scoured SO for an answer to what I think is probably a ridiculous oversight, but here goes.
I have a ListView that I'm populating with an ArrayAdapter that I'm building out of a list of objects I'm using elsewhere in my application. I have checked via getCount that there are items in the adapter, both before and after I call .setAdapter(). Nothing is showing up in my application however.
My main layout res/layout/playlistview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/playlist_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#80000000"
android:gravity="center"
android:orientation="horizontal" >
<ListView
android:id="#+id/playlistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#206"
android:background="#602" >
</ListView>
</LinearLayout>
(I set the colors so I could see what's going on more easily)
the textview for each item res/layout/singlelistitem:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/single_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:padding="5dp"
android:background="#206">
</TextView>
and the code I use to populate it:
private ListView playlistView;
private void buildPlaylistView() {
playlistView = (ListView)findViewById(R.id.playlistview);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.singlelistitem, R.id.single_item, playlist.titlesAsArray());
playlistView.setAdapter(adapter);
playlistView.setVisibility(View.VISIBLE);
adapter.notifyDataSetChanged();
((ArrayAdapter<String>)playlistView.getAdapter()).notifyDataSetChanged();
}
playlist.titlesAsArray() does return String[] and it works.
I have both of the .notifyDataSetChanged() in there, since I found that on SO and gave it a try.
When I change the android:layout_height in the ListView object in my XML to wrap_content, I see only the opaque background that is in the LinearLayout that wraps it. When I set the ListView android:layout_height to match_parent, the whole screen is #206 (magentish).
When i check getCount() on the adapter before setAdapter() it says there are items. When I check it after, from the view itself, it says there are the same number of items. I'm totally lost on this one, but nothing is displayed.
Try changing from android:orientation="horizontal" to android:orientation="vertical" this may fix.
I have got something like this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/chooseBirthDateText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
style="#style/mediumText"
android:gravity="center_horizontal"
android:text="#string/choose_birth_date" />
</TableRow>
</TableLayout>
</ScrollView>
i would like to add some more rows, but only after some time(lets say 10 sec). I thought to make those rows invisible at first and then make them appear. But in that way my scrollView is not working as i want(i can scroll down even if nothing is below - since rows are invisible)
So i thought to make rows that i want to add in second file, load them in middle time and add them after tableRow1 in moment they have to appear. Unfortunately i have got no idea how to do that(i am talking about connecting 2 files, not creating second one in java) :/
There are two modes to hide a view:
INVISIBLE: This view is invisible, but it still takes up space for layout purposes.
GONE: This view is invisible, and it doesn't take any space for layout purposes.
http://developer.android.com/reference/android/view/View.html#setVisibility(int)
I think GONE will help you.
You should try like this.let me know it is helpful or not?
for(int i = 0; i < _attributeList.size();i++){
TableRow newRow = new TableRow(getApplicationContext());
newRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
newCheckBox = new CheckBox(getApplicationContext());
TextView feeTypeText = new TextView(getApplicationContext());
feeTypeText.setText(jsonObj.getString("feeType"));
feeTypeText.setTextColor(Color.BLACK);
feeTypeText.setTextSize(16f);
feeTypeText.setTypeface(tf);
TextView dueAmountText = new TextView(getApplicationContext());
dueAmountText.setText(jsonObj.getString("dueAmount"));
dueAmountText.setTextColor(Color.BLACK);
dueAmountText.setTextSize(16f);
dueAmountText.setTypeface(tf);
TextView dueDateText = new TextView(getApplicationContext());
dueDateText.setText(jsonObj.getString("dueDate"));
dueDateText.setTextColor(Color.BLACK);
dueDateText.setTextSize(16f);
dueDateText.setTypeface(tf);
newRow.addView(newCheckBox,(new LayoutParams(0,LayoutParams.WRAP_CONTENT,0.8f)));
newRow.addView(feeTypeText,(new LayoutParams(0,LayoutParams.WRAP_CONTENT,0.8f)));
newRow.addView(dueAmountText,(new LayoutParams(0,LayoutParams.WRAP_CONTENT,1.0f)));
newRow.addView(dueDateText,(new LayoutParams(0,LayoutParams.WRAP_CONTENT,1.0f)));
attributeTable.addView(newRow); }
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.