How to remove the separator line in the spinner? - android

How to remove the separator line in the spinner?
For example, how can I remove/control these white separator lines?
P.S. This is the row layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black">
<TextView
android:id="#+id/catalog_spinner_item_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="11dp"
android:text="#string/CatalogSpinnerItemRowDefaultText"
android:textSize="18sp"
android:gravity="center_vertical"/>
</LinearLayout>

public View getView(int position, View row, ViewGroup container) {
row=(View) inflater.inflate(R.layout.row_layout_spinner_filter, null);
TextView tv=(TextView) row.findViewById(R.id.textview_spinner_filter_item_name);
if(container!=null&&(container instanceof ListView)){
ListView lv=null;
try{
lv=(ListView)container;
}catch(Exception e){}
if(lv!=null){
lv.setDivider(drawable);
lv.setDividerHeight(height);
}
}
tv.setText(getItem(position));
return row;
}
ViewGroup container comes as ListView or Spinner, so you can catch listview and edit divider.

use in Spinner's xml
android:backgorund="#null"

Define a style as mentioned by Kunal, then refer to that style in your spinner as android:style = " "
or you can use android:divider and android:dividerHeight in your spinner to control its attributes/ remove them.
Or you can set the divider to android:color/transparent as well.

Related

Text color change not reflecting in list view

I changed the text color and its not reflecting.. still showing black by default.Please help
I edited the "android.R.layout.simple_list_item_1" xml file. Is that enough or should i change something else to make it work?
android:id="#android:id/text1"
android:textColor="#FFFFFF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:minHeight="?android:attr/listPreferredItemHeightSmall" />
You can do that programmatically by overriding the getView of ArrayAdapter like the following.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
android.R.layout.simple_list_item_1, yourList) {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(android.R.id.text1);
text.setTextColor(Color.WHITE);
return view;
}
};
you have to change second argument of ArrayAdapter with selfmade xml textview file.
step 1.inside res in layout make textview_blue.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20sp"
android:textColor="#00f">
</TextView>
step 2.
ArrayAdapter adapter=new ArrayAdapter<>(getApplicationContext(),R.layout.textview_blue,arraylist_yours);
step 3.
listview.setAdapter(adapter);
sure this code is work for you, you may change color in xml as per your desire.
this answer will helpful correctly as per your requirement.

Change view background color into a listview

I'm trying to change background color on a view component, but not success
public View getView(int position, final View convertView, ViewGroup parent) {
View view = convertView;
try {
if (view == null) {
LayoutInflater vi = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.listview_accounts, null); // --CloneChangeRequired(list_item)
}
final Account listItem = (Account) mList.get(position); // --CloneChangeRequired
if (listItem != null) {
int color = listItem.getColor();
View vColor = (View) view
.findViewById(R.id.lv_account_view_color);
vColor.setBackgroundColor(color);
}
}
} catch (Exception e) {
}
return view;
}
I can set some text in textview, but set color not working.
Can anybody helps me how to set the color? Thanks
The example color used is: -16711717
edit
Listview Item layout:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:id="#+id/lv_account_view_color"
android:layout_width="#dimen/activity_horizontal_margin"
android:layout_height="wrap_content"
android:background="#167117" />
<TextView
android:id="#+id/lv_account_tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:textColor="#color/black" />
</LinearLayout>
background cannot be setted in xml, it's a dynamic color
Try this: vColor.setBackgroundColor(Color.parse("#yourcolorcode"));
You can directly set the background color of the component in the listview_accounts.xml file of your project. For example
<component>
android:background="#color/color_name"
</component>
You have to make a color.xml file in your values folder(maybe already present) and add the color value ex:-16711717.
try this and let me know
<View
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#167117" />
you can find solution on This link
Just you have to change one thing. In delete.onclick method replace list.removeView(customView); with Customview.setbackground(Color.red); etc. This may help you. Best of luck.

Why ArrayAdapter doesn't use the TextView passed to it?

I have a navigation drawer which uses a ListView defined in the main activity layout:
<!-- Navigation drawer (left) -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/darker_gray"
android:dividerHeight="1dp"
android:background="#e5e5e5"/>
and I populate it like this:
navMenuItems = getResources().getStringArray(R.array.NavMenuItems);
navDrawerList = (ListView) findViewById(R.id.left_drawer);
// Set the adapter for the list view
navDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.nav_list_item, navMenuItems));
As the ArrayAdapter needs a TextView resource ID to be passed to it, I use a separate layout file with only a TextView in it for menu items:
nav_list_item.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/nav_menu_text"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="right"
android:gravity="right"
android:layoutDirection="rtl"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:paddingRight="8dp"
android:textColor="#android:color/white"
android:textSize="50sp"
android:textIsSelectable="true"
android:textAlignment="textStart"
android:textDirection="anyRtl" >
</TextView>
BUT, the TextView has no effect whatsoever and the menu items are shown the same no matter what attribute is changed!
Why is this happening? What am I doing wrong here?
In Resource, you should give layout instead of id of text view
new ArrayAdapter<String>(this, R.layout.'yourlayoutname', navMenuItems)
You should add a param to ensure that the adapter knows what view to map the contents of the navitem.
As the 3rd param, add the id of the textview's id. Like this:
new ArrayAdapter<String>(this, R.layout.nav_list_item, R.id.nav_menu_text, navMenuItems)
instead of
new ArrayAdapter<String>(this, R.layout.nav_list_item, navMenuItems)
Im not sure about this, but if you don't want to use the textview's id, it might work naming the id field to "text01" which is the id of the android.R.layout.simple_list_item_1's textview.
try this:
new ArrayAdapter<String> (Context context, R.layout.nav_list_item, R.id.nav_menu_text, navMenuItems);
Hope this helps you...
I found a solution:
I made a custom adapter for navigation list and in its getView() (#override) used my textView:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
Log.d("Log", "Null v");
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.nav_list_item, null);
}
String s = values.get(position);
TextView textView = (TextView) v.findViewById(R.id.nav_menu_text);
textView.setText(s);
return v;
}
Now the attributes in textView take effect.

How to wrap text using simple_list_item_multiple_choice?

I'm using a SimpleCursorAdapter to display a single CheckedTextView. I know this is done best using simple_list_item_multiple_choice and android.R.id.text1.
adapter = new SimpleCursorAdapter(getApplicationContext(),
android.R.layout.simple_list_item_multiple_choice, rules,
new String[]{Constants.KEY_RULE}, new int[]{android.R.id.text1});
If the text from KEY_RULE is more than two lines, android doesn't wrap, instead it hides it. Is there an easy work-around for this without having to implement my own adapter?
Find my xml code below:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="#+id/header" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="#string/rule_selection_for_revision_list_title"
android:padding="4dip" android:background="#000000" android:textColor="#ffffff" android:textStyle="bold" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_weight="1.0" />
<TextView android:textSize="18sp" android:textStyle="bold"
android:id="#id/android:empty" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center_vertical|center_horizontal"
android:text="There are no rules to consider." />
</LinearLayout>
Is there any way I can at least reduce the font size so that it fits to two lines?
There are several options.
You can define your custom layout for item in the list. This allows you to fully customize your item UI. More details can be found in List View tutorial.
The other approach can be used if you still want to use standard item layout but only fix one small thing in it. You can extend Adapter and modify the view in getView function. Here is an example:
class MySimpleCursorAdapter extends SimpleCursorAdapter
{
public MySimpleCursorAdapter(Context ctx, int layout,
Cursor cursor, String [] from, int [] to)
{
super(ctx, layout, cursor, from, to);
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = super.getView(position, convertView, parent);
TextView textView = (TextView)view.findViewById(android.R.id.text1);
//You can increase number of lines in the text view
textView.setMaxLines(5);
LayoutParams params = textView.getLayoutParams();
if(params.height > 0)
{
int height = params.height;
params.height = LayoutParams.WRAP_CONTENT;
textView.setLayoutParams(params);
textView.setMinHeight(height);
}
//Or you can make your font smaller
textView.setTextSize(customTextSize);
//or whatever you like, even apply new custom style
//...
return view;
}
}
You should probably choose the first approach (custom layout), but sometimes the second approach is feasible too.
You don't need to implement a custom Adapter. Just define a custom layout for the list items and pass it to the adapter instead of android.R.layout.simple_list_item_multiple_choice.
You can search the Android sources (come with the SDK on you computer) to how the original simple_list_item_multiple_choice layout looks like and adapt it to your needs.

ListView and its text color

I have CustomListView ,ie contain a background image and TextView,
When an item is selected i need to change the background image and font color, currently i can change the background of selected row of the listview using an xml, but i can't change the text color.
By default my text color is black when am clicking an item in listview i need to change the text color to white.
am using following layout for my customlistview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="29dp"
android:id="#+id/appcategoryLinearLayout"
android:background="#drawable/appcategorybg1"
android:gravity="left|center_vertical"
>
<TextView
android:gravity="left|center_vertical"
android:text="fdsfsdfsdfdsfdsfdsf"
android:paddingLeft="8dp"
android:textSize="8dp"
android:textColor="#color/black"
android:id="#+id/appCategoryNameTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
The only way to write your own ListAdapter and write custom controls which would have the visual properties you define.
I am not sure if this will help you but you can do some thing like this
Use TextView variables as global
TextView t ;
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
if(t != null)
{
//reset the color to black
}
LinearLayout lay = (LinearLayout)v;
t = lay.getChildAt(0);
//now set text to bold
}
};

Categories

Resources