Changing background of drawable instance in ListView - android

I have a drawable resource drawable/badge.xml which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<solid android:color="#000" />
</shape>
...and is used inside a layout file layout/badge.xml which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="18dp"
android:layout_height="18dp" >
<View
android:id="#+id/badge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/badge" />
<TextView
android:id="#+id/badge_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:textColor="#fff"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
Inside a BaseExpandableListAdapters getChildView method there is this code:
...
LinearLayout badgeContainer = (LinearLayout) convertView.findViewById(R.id.badge_container);
for (String property : properties) {
RelativeLayout badge = (RelativeLayout) inflater.inflate(R.layout.badge, badgeContainer, false);
badge.setLayoutParams(new LinearLayout.LayoutParams(50, 50));
((TextView) badge.findViewById(R.id.badge_text)).setText(course.property);
badge.findViewById(R.id.badge).getBackground().setColorFilter(getColorResourceByProperty(property), PorterDuff.Mode.DST);
badgeContainer.addView(badge);
}
...
So what I'm trying to do is change the background color of the drawable badge for each property, but this code still yields in all badges to have a black background. What am I doing wrong? I've also tried many other PorterDuff modes without results.

After fighting some more I got it working like this:
drawable/circle.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="#fff" />
</shape>
layout/badge.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/badge_text"
android:layout_width="16dp"
android:layout_height="16dp"
android:gravity="center_vertical|center_horizontal"
android:background="#drawable/circle"
android:textColor="#color/white"
android:textSize="12sp"
android:layout_marginLeft="1dp"
android:textStyle="bold" />
and inside the adapter:
LinearLayout badgeContainer = (LinearLayout) convertView.findViewById(R.id.badge_container);
for (int i = 0; i < course.properties.length; i++) {
TextView badge = (TextView) inflater.inflate(R.layout.badge, badgeContainer, false);
badge.setText(course.properties[i]);
int colorID = context.getResources().getIdentifier("property_" + course.properties[i], "color", context.getPackageName());
badge.getBackground().setColorFilter(context.getResources().getColor(colorID), Mode.MULTIPLY);
badgeContainer.addView(badge);
}

Related

How to draw border for circular image view?

I am using drawable as image background for giving border but its not working as required (circle is not perfect).
Recycler view item layout
<data>
<variable
name="news"
type="com.android.mvvm.model.NewsItem" />
<variable
name="clickListener"
type="com.android.common.util.RecyclerViewOnItemClickHandler"></variable>
</data>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circular_image_selected"
android:layout_width="100dp"
android:layout_height="100dp"
android:onClick="#{clickListener.onClick}"
android:src="#{news.thumb}" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circular_image_unselected"
android:layout_width="100dp"
android:layout_height="100dp"
android:onClick="#{clickListener.onClick}"
android:src="#{news.thumb}"
android:visibility="gone" />
</FrameLayout>
Adapter's onBindViewHolder method where i am setting background to the image view on item selected
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof RecyclerViewHolder) {
NewsItem item = list.get(position);
RecyclerViewHolder newsViewHolder = (RecyclerViewHolder) holder;
if (item.isSelected) {
CircleImageView img = (CircleImageView) newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_unselected);
newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_unselected).setVisibility(View.VISIBLE);
img.setBackground(context.getResources().getDrawable(R.drawable.selected_img_bg));
} else {
CircleImageView img = (CircleImageView) newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_selected);
img.setColorFilter(Color.argb(150, 155, 155, 155), PorterDuff.Mode.SRC_ATOP);
newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_unselected).setVisibility(View.INVISIBLE);
}
newsViewHolder.getBinding().setVariable(BR.clickListener,
new RecyclerViewOnItemClickHandler<>(item, position, listener));
newsViewHolder.getBinding().setVariable(BR.news, item);
newsViewHolder.getBinding().executePendingBindings();
}
}
Drawable for image background
<?xml version="1.0" encoding="utf-8"?><shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#android:color/transparent" />
<stroke android:color="#android:color/holo_red_dark" android:width="3dp"/>
<size
android:width="100dp"
android:height="100dp"/>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:useLevel="false"
android:thickness="7.8dp"
android:innerRadius="0dp"
>
<solid
android:color="#F00"
/>
<stroke
android:width="1dip"
android:color="#FFF" />
use this as background to you image... increase thickness accordingly.. or if this doesn't work retain the previous background xml and add android:padding around 10 to 15 dp in your imageview
i solve this by placing imageview into relativelayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_margin="5dp"
android:padding="2dp"
android:background="#drawable/imageborder"
android:src="#drawable/placeholder"
android:id="#+id/notificator_image"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<stroke android:width="2dp"
android:color="#cc195d" />
</shape>

Draw custom line between two elements in TableLayout Android

I have an activity with events organised in a timeline. But it looks ugly.
I want to design a more beautiful timeline like this one.
Is there any simple way or a library to draw lines between elements like in my example?
<ScrollView
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#+id/text_data"
android:layout_above="#+id/button_trimite"
android:id="#+id/scroll_timeline"
android:layout_marginBottom="7dp"
>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/timelineTable"
>
</TableLayout>
</ScrollView>
This is my xml. But my TableLayout is generated dynamically because I need to sort my events.
for (final Event e : events) {
if(e.getDate().equals(dataComp)) {
//tablerow with event entry
final TableRow row = new TableRow(getActivity());
row.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
if (indexForDrawable % 2 == 0)
row.setBackgroundResource(R.drawable.marcaj_event_albastru);
else
row.setBackgroundResource(R.drawable.marcaj_event_portocaliu);
TextView txtEvent = new TextView(getActivity());
txtEvent.setText(" "+ e.getHour() +"-"+e.getType()+"-"+e.getTitle());
txtEvent.setTextColor(Color.BLACK);
txtEvent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, trEvent);
txtEvent.setTypeface(Typeface.create(tf, Typeface.BOLD));
row.addView(txtEvent);
row.setClickable(true);
final String date = e.getDate(), hour = e.getHour(), title = e.getTitle(),
type = e.getType(), descriere = e.getDescriere();
final int finalResource = resource;
final int finalIndexForDrawable = indexForDrawable;
row.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
row.setBackground(getActivity().getResources().getDrawable(finalResource));
showPopup2(date, hour, type, title, descriere, row, finalIndexForDrawable);
}
});
timelineTable.addView(row, new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
indexForDrawable++;
}
else {
//tablerow with date
final TableRow row = new TableRow(getActivity());
row.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
TextView txtEvent = new TextView(getActivity());
// txtEvent.setText("\n" + dataSplit1[0]+months.indexOf(dataSplit11));
txtEvent.setText("\n" + e.getDate().substring(0, 5));
txtEvent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, trDate);
row.addView(txtEvent);
timelineTable.addView(row, new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
dataComp = e.getDate();
//tablerow with event entry
final TableRow row3 = new TableRow(getActivity());
row3.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
if (indexForDrawable % 2 == 0)
row3.setBackgroundResource(R.drawable.marcaj_event_albastru);
else
row3.setBackgroundResource(R.drawable.marcaj_event_portocaliu);
TextView txtEvent3 = new TextView(getActivity());
txtEvent3.setText(" "+ e.getHour() +"-"+e.getType()+"-"+e.getTitle());
txtEvent3.setTextColor(Color.BLACK);
txtEvent3.setTextSize(TypedValue.COMPLEX_UNIT_DIP, trEvent);
txtEvent3.setTypeface(Typeface.create(tf, Typeface.BOLD));
row3.addView(txtEvent3);
row3.setClickable(true);
final String date3 = e.getDate(), hour3 = e.getHour(), title3 = e.getTitle(),
type3 = e.getType(), descriere3 = e.getDescriere();
timelineTable.addView(row3, new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
indexForDrawable++;
}
You may have to create your own custom adapter but I am using array adapter for your reference. Also giving item layout for list view, hope you will manage your code accordingly.
items.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#android:color/black" />
<View
android:id="#+id/view1"
android:layout_width="7dp"
android:layout_height="7dp"
android:layout_centerVertical="true"
android:layout_marginLeft="7dp"
android:background="#drawable/dot" />
</RelativeLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="20dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
dot.xml which is a drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<stroke
android:width="1dp"
android:color="#android:color/black" />
<solid android:color="#android:color/white" />
And in acivity you can use adapter like this:
list.setAdapter(new ArrayAdapter<String>(this, R.layout.item, R.id.textView1, items));
Hope this helped!
If you just want a line displayed i recommend you to create a Drawable for this.
Heres a little example:
Layout file
<?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="match_parent"
android:background="#drawable/line">
</LinearLayout>
and the line.xml Drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="3dp">
<shape >
<stroke android:width="1dp" android:color="#android:color/holo_purple"/>
</shape>
</item>
<item android:left="4dp">
<shape>
<solid android:color="#ffffff"/>
</shape>
</item>
</layer-list>
The Layer-list may also be changed to use up additional Drawables as the ones you are already using.
An example using draw-9 might look like this:
line.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<nine-patch android:src="#drawable/point" android:dither="true"/>
</item>
<!-- <item android:left="3dp">
<shape >
<stroke android:width="1dp" android:color="#android:color/holo_purple"/>
</shape>
</item>
<item android:left="4dp">
<shape>
<solid android:color="#ffffff"/>
</shape>
</item> -->
</layer-list>
Layout:
<?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="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:background="#drawable/line" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:background="#drawable/line"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_gravity="center_horizontal"
android:background="#drawable/line" />
</LinearLayout>
and my point.9.png
to apply a draw-nine-patch you must mark the parts to be streched with black color on the borders.

Draw circles inside TextView

I have a calendar that looks like this:
The Class that draws this Calendar is called MonthView and is a TableLayout:
class MonthView extends TableLayout{...}
The function that creates the calendar is shown below:
TextView btn;
TableRow tr;
void DisplayMonth(boolean animationEnabled){
...
for(int i = 0; i < 6; i++){
if(day > cal.getActualMaximum(Calendar.DAY_OF_MONTH))
break;
tr = new TableRow(context);
tr.setWeightSum(0.7f);
for(int j = 0; j < 7; j++){
btn = new TextView(context);
...
}
}
The function that changes the color of the background day is below:
public void changeBackgroundDay(List<Class> classes){
for(int i = 0; i < getChildCount; i++){
TableRow row = (TableRow)getChildAt(i);
for(int j = 0; j < row.getChildCount(); j++){
TextView t = (TextView)row.getChildAt(j);
for(int tam = 0; tam < classes.size(); tam++){
Class class = classes.get(tam);
// ---- THIS IS THE PART THAT I WANT TO CHANGE ----//
if(class.getTypePlanning().equals("null"){
t.setBackgroundColor(Color.parseColor("#777777");
}
else if(class.getTypePlanning().equals("R")){
t.setBackgroundColor(Color.parseColor("#2477B2");
}
// -----------------------------------------------//
...
}
}
}
}
I want to, instead of just changing the background color of the TextView, draw 4 circles on this TextView. In some cases, it can be drawn just 2 or 3. For example, like is shown in the pictures:
I've tried to make a Layer list with items that contains shape and color and defined this Layer list as the background of the TextView, but it didn't work really well.
The Layer list xml is below:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layerlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<item android:id="#+id/itemnaoplanejado"
android:bottom="1dp" android:right="1dp">
<shape android:shape="oval" android:visible="false">
<size android:width="2dp"
android:height="2dp"/>
<solid android:color="#777777"/>
</shape>
</item>
<item android:id="#+id/itemplanejado"
android:bottom="1dp" android:left="1dp">
<shape android:shape="oval" android:visible="false">
<size android:width="2dp"
android:height="2dp"/>
<solid android:color="#8CC9F3"/>
</shape>
</item>
....
</layer-list>
On the function changeBackgroundDay I do this:
public void changeBackgroundDay(List<Class> classes){
...
if(class.getTypePlanning().equals("null"){
LayerDrawable layerDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.layerlistday);
layerDrawable.findDrawableByLayerId(R.id.itemnotplanned).setVisible(true, false);
t.setBackground(layerDrawable);
}
}
Any ideas?
Thanks in advance.
Tyr this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/num_txt"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="0dp"
android:background="#drawable/bg_red"
android:gravity="center"
android:text="My name is NON"
android:textColor="#FFFFFF"
android:textSize="10dp" />
</RelativeLayout>
</RelativeLayout>
save in drwable bg_red.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="10dip"/>
<stroke android:color="#FF0000" android:width="5dip"/>
<solid android:color="#FF0000"/>
</shape>
Edited Code -----
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="#+id/num_txt"
android:layout_width="185dp"
android:layout_height="185dp"
android:layout_alignParentTop="true"
android:layout_marginTop="163dp"
android:background="#drawable/bg_red"
android:gravity="center"
android:text="My name is NON"
android:textColor="#FFFFFF"
android:layout_marginLeft="10dp"
android:textSize="10dp" />
<TextView
android:id="#+id/TextView02"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/TextView01"
android:layout_marginRight="90dp"
android:layout_marginTop="122dp"
android:background="#drawable/bg_red"
android:gravity="center"
android:text="My name is NON"
android:textColor="#FFFFFF"
android:textSize="10dp" />
<TextView
android:id="#+id/TextView01"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignTop="#+id/num_txt"
android:layout_toRightOf="#+id/num_txt"
android:background="#drawable/bg_red"
android:gravity="center"
android:text="My name is NON"
android:textColor="#FFFFFF"
android:textSize="10dp" />
</RelativeLayout>

Custom tabs in a Android App

I'm build a android app with a tabhost and It works well. The problem is that I want to customize the tabhost with a selector xml file but I dont know how I do.
My tabhost is this:
http://i.stack.imgur.com/xYMuh.png
And I would like to have this:
http://i.stack.imgur.com/UJu1K.png
My code of MainActivity as I create the tabs through a layout:
// Tab1
View tab1 = getLayoutInflater().inflate(R.layout.tab_indicator, null);
TextView title1 = (TextView)tab1.findViewById(R.id.titleTab);
title1.setText("¿Qué hacer?");
ImageView img1 = (ImageView)tab1.findViewById(R.id.iconTab);
img1.setImageResource(R.drawable.what);
mTabHost.addTab(mTabHost.newTabSpec("que hacer").setIndicator(tab1),
HacerFragment.class, null);
// Tab2
View tab2 = getLayoutInflater().inflate(R.layout.tab_indicator, null);
TextView title2 = (TextView)tab2.findViewById(R.id.titleTab);
title2.setText("¿A dónde ir?");
ImageView img2 = (ImageView)tab2.findViewById(R.id.iconTab);
img2.setImageResource(R.drawable.where);
mTabHost.addTab(mTabHost.newTabSpec("donde").setIndicator(tab2),
DestacadoFragment.class, null);
// Tab3
View tab3 = getLayoutInflater().inflate(R.layout.tab_indicator, null);
TextView title3 = (TextView)tab3.findViewById(R.id.titleTab);
title3.setText("Lee tu mapa");
ImageView img3 = (ImageView)tab3.findViewById(R.id.iconTab);
img3.setImageResource(R.drawable.read);
mTabHost.addTab(mTabHost.newTabSpec("mapa").setIndicator(tab3),
LectorFragment.class, null);
// Tab4
View tab4 = getLayoutInflater().inflate(R.layout.tab_indicator, null);
TextView title4 = (TextView)tab4.findViewById(R.id.titleTab);
title4.setText("Captura");
ImageView img4 = (ImageView)tab4.findViewById(R.id.iconTab);
img4.setImageResource(R.drawable.capture);
mTabHost.addTab(mTabHost.newTabSpec("captura").setIndicator(tab4),
CapturaFragment.class, null);
And my tab_indicator.xml (each tab):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:background="#color/tabhost_background"
android:padding="5dp" >
<ImageView android:id="#+id/iconTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/buscar24" />
<TextView android:id="#+id/titleTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_below="#+id/iconTab"
style="#drawable/tab_selector" />
</RelativeLayout>
Thanks!!
tab_indicator.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relative"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_selector"
android:padding="5dp" >
<ImageView
android:id="#+id/iconTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:clickable="false"
android:focusable="false"
android:background="#drawable/image_selector" />
<TextView
android:id="#+id/titleTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/iconTab"
android:layout_centerHorizontal="true"
android:clickable="false"
android:focusable="false"
android:text="HELLO" />
</RelativeLayout>
background_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/selected_thick_bg" android:state_selected="true"> </item>
<item android:drawable="#drawable/unselected_light_bg" android:state_selected="false">
</item>
</selector>
image_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/selected_thick_image" android:state_selected="true"> </item>
<item android:drawable="#drawable/unselected_light_image"
android:state_selected="false"> </item>
</selector>

ListView performance lower on 4.2 than on 4.1

I have just upgraded on Android 4.2 on my Galaxy Nexus and ListView seems to be slower than It used to be on 4.1. This bindView method was perfect fast on 4.1, on new 4.2 I see small glitches. I have tried to explicitly enable hardware acceleration in AndroidManifest.xml, but it dit not help much. People (Contacts) app works perfect on 4.2, which I guess is also implemented by extended android.support.v4.widget.CursorAdapter. I have also already tried to change android.support.v4.widget.CursorAdapter for android.widget.CursorAdapter without visible improvement.
#Override
public void bindView(View view, Context context, Cursor cursor) {
final ViewHolder holder = (ViewHolder) view.getTag();
holder.nameView.setText(cursor.getString(mStreetColumnIndex));
holder.townView.setText(cursor.getString(mTownColumnIndex));
if (mDistanceColumn != null) {
float distance = cursor.getFloat(mDistanceColumn);
String distanceUnit;
if (distance >= 1000) {
distance /= 1000;
distanceUnit = " km";
} else {
distanceUnit = " m";
}
String decimalString = mDecimalFormat.format(distance);
holder.distanceView.setText(decimalString + distanceUnit);
holder.distanceView.setVisibility(View.VISIBLE);
} else {
holder.distanceView.setVisibility(View.GONE);
}
// read only brand first letter to be faster
cursor.copyStringToBuffer(mBrandColumnIndex, mBuffer);
if (mBuffer.sizeCopied > 0) {
if (mBuffer.data[0] == 'a') {
holder.logoImgView.setImageResource(R.drawable.agip);
} else {
holder.logoImgView.setImageResource(R.drawable.papoil);
}
} else {
holder.logoImgView.setVisibility(View.INVISIBLE);
}
}
EDIT: added row layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="#dimen/row_height"
android:background="#drawable/bg_list_selector"
android:layout_marginRight="#dimen/screen_padding"
android:layout_marginLeft="#dimen/screen_padding"
android:paddingLeft="#dimen/screen_padding">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginRight="#dimen/screen_padding"
android:layout_toLeftOf="#+id/txtDistance"
android:orientation="vertical"
>
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/list_text_primary_size"
android:textStyle="bold"
/>
<TextView
android:id="#+id/txtTown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/list_text_primary_size"
/>
</LinearLayout>
<TextView
android:id="#+id/txtDistance"
android:layout_toLeftOf="#+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#color/grey_dark"
android:textSize="13sp"
android:textStyle="bold"
android:layout_marginRight="#dimen/screen_padding"/>
<ImageView
android:id="#+id/imgLogo"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/agip"
android:background="#color/grey_dark"
/>
</RelativeLayout>
EDIT 2:
here is traceview http://goo.gl/UmS3w
which was made using http://goo.gl/Yoe1u
It was caused by too much complicated windowBackground, which was:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/bg_repeat">
</item>
<item>
<shape>
<gradient android:startColor="#0affffff" android:endColor="#0a000000"
android:type="radial" android:gradientRadius="500"/>
</shape>
</item>
<item>
<shape>
<gradient android:startColor="#1effffff" android:endColor="#1e000000"
android:type="linear" android:angle="270"/>
</shape>
</item>
</layer-list>
and bg_repeat.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/bg"
android:tileMode="repeat"/>
Thanks all for help!

Categories

Resources