get Inflate Exception with gridlayout - android

Hi Guys i got the android.view.InflateException: Binary XML file line #1: Error inflating class linearlayout, Caused by: java.lang.ClassNotFoundException: android.view.linearlayout in loader dalvik.system.PathClassLoader[/data/app/com.project.news-2.apk] in the indicate line below.
Have a look and
HomeActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
another method inside of HomeActivity
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dashboard_home ,(ViewGroup) findViewById(R.id.layout_root));
GridView grid = (GridView) layout.findViewById(R.id.gridview);
adapter = new HomeAdapter(this);
adapter.setItems(config); grid.setAdapter(adapter);
HomeAdapter
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder
if (convertView == null) { // if it's not recycled,
convertView = mInflater.inflate(R.layout.dashboard_home, null); //exception
convertView.setLayoutParams(new GridView.LayoutParams(90, 90));
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.titleIcon);
holder.icon = (ImageView) convertView.findViewById(R.id.imageIcon);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout style="#style/TitleBar">
<ImageView style="#style/TitleBarLogo"
android:contentDescription="Text testing" />
<ImageView style="#style/TitleBarSeparator" />
<TextView style="#style/TitleBarText" />
<ImageButton style="#style/TitleBarAction"
android:contentDescription="#string/description_about" android:src="#drawable/info"
android:onClick="onClickAbout" />
</LinearLayout>
<GridView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/gridview"
android:numColumns="2"
/>
</LinearLayout>
dashboard_home.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="10dp">
<ImageView android:id="#+id/imageIcon" android:layout_width="50dip"
android:layout_height="50dip" android:layout_alignParentRight="true"
android:layout_marginRight="3dp" />
<TextView android:id="#+id/titleIcon" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:layout_alignParentLeft="true" android:layout_marginLeft="3dp"
android:textColor="#FFF" />
</LinearLayout>

Remove these two lines and run your code in the HomeActivity.
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dashboard_home ,(ViewGroup) findViewById(R.id.layout_root));
the exception happens why because you are inflating the dashboard_home.xml into that itself..

Related

How to declare imageview without set/inflate the layout?

is there any code to declare the imageview and set imageresource without inflate the layout ?
i am create listview adapter in other layout, so i didnt inflate the layout.
but ineed to set image to the imageview.
this is my code but its not working
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_item_list_request, container, false);
setHasOptionsMenu(true);
rlRequestWorkflow = (RelativeLayout)getActivity().findViewById(R.id.rlListRequestWorkflow);
listPhoto = (ImageView)getActivity().findViewById(R.id.listPhoto);
rlRequestWorkflow.addView(listPhoto);
}
this is my current layout (main class)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/flRequest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context="com.ITK.SMP.Native.Workflow.ListRequest">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:background="#ffffff">
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lvRequest"
android:choiceMode="singleChoice"
android:nestedScrollingEnabled="false"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
this is listadapter class
public class ListRequestAdapter extends ArrayAdapter<ListRequestItem> {
ImageView listPhoto;
public ListRequestAdapter(Context context, List<ListRequestItem> items)
{
super(context, R.layout.style_fragment_list_request, items);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if(convertView == null) {
// inflate the GridView item layout
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.style_fragment_list_request, parent, false);
// initialize the view holder
viewHolder = new ViewHolder();
viewHolder.tvTanggal = (TextView) convertView.findViewById(R.id.tvTanggalRequest);
viewHolder.tvTipe = (TextView) convertView.findViewById(R.id.tvTipeRequest);
viewHolder.tvStatus = (TextView) convertView.findViewById(R.id.tvStatus);
viewHolder.permitid = "";
convertView.setTag(viewHolder);
} else {
// recycle the already inflated view
viewHolder = (ViewHolder) convertView.getTag();
}
// update the item view
ListRequestItem item = getItem(position);
viewHolder.tvTanggal.setText(item.tanggal);
viewHolder.tvTipe.setText(item.tipe);
viewHolder.tvStatus.setText(item.status);
viewHolder.permitid = item.permitid;
return convertView;
}
private static class ViewHolder {
TextView tvTanggal;
TextView tvTipe;
TextView tvStatus;
String permitid;
}
}
this is the imageview in the listadapterlayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="reqtag"
android:id="#+id/rlListRequestWorkflow"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:weightSum="1"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.2"
android:orientation="vertical"
android:layout_height="wrap_content">
<!--ImageView here-->
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/listPhoto"
android:layout_width="65dp"
android:layout_height="63dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_menu_camera"
android:layout_marginTop="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.8"
android:orientation="vertical"
android:layout_height="wrap_content">
<!--All textViews here-->
<TextView
android:layout_width="100dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Type"
android:textSize="18dp"
android:fontFamily="sans-serif"
android:textColor="#color/black"
android:id="#+id/tvTipeRequest"
android:width="130dp" />
<TextView
android:layout_width="100dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Date"
android:fontFamily="sans-serif"
android:id="#+id/tvTanggalRequest"
android:textSize="15dp"
android:width="130dp" />
<TextView
android:layout_width="100dp"
android:layout_weight="1"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:text="Status"
android:textSize="15dp"
android:fontFamily="sans-serif"
android:id="#+id/tvStatus"
android:layout_column="38" />
</LinearLayout>
</LinearLayout>
any help would be appreciated
If you don't want to inflate your imageview, then pass your imageview in the constructor of class, and set the image from there.
Suppose, MainActivity is the class where your image view is present
MainActivity.class
ImageView imageview;
imageview=(ImageView)findViewById(R.Id.imageview);
new ListAdapter(imageview);
ListAdapter.class
ImageView imageview;
//constructor
public ListAdapter(ImageView imageview){
this.imageview=imageview;
}
//now you can use imageview to set image
Edit this:-
rlRequestWorkflow = (RelativeLayout)view.findViewById(R.id.rlListRequestWorkflow);
listPhoto = (ImageView)view.findViewById(R.id.listPhoto);

Cant change View background colour programmatically

Im an android newbie so please forgive me...
This is my code:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.adapter_who_row, null);
viewHolder.nameTextView = (TextView) convertView.findViewById(R.id.text);
viewHolder.companyTextView = (TextView) convertView.findViewById(R.id.whoRowCompany);
viewHolder.dotView = convertView.findViewById(R.id.whoRowDot);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
String textToShow = dataArray.get(position);
viewHolder.nameTextView.setText(textToShow);
viewHolder.dotView.setBackgroundColor(getResources().getColor(R.color.red));
viewHolder.companyTextView.setText("Test");
return convertView;
}
class ViewHolder {
TextView nameTextView;
TextView companyTextView;
View dotView;
}
dotView doesn't change its colour...
However, the two textVies does change their text.
What could it be?
Edit:
The xml is holding two editTexts and one View.
Below is my xml:
<?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="wrap_content" android:layout_centerVertical="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.85"
android:layout_gravity="center"
android:gravity="center">
<View
android:id="#+id/whoRowDot"
android:layout_width="40px"
android:layout_height="40px"
android:backgroundTint="#color/noteColor">
</View>
<!--android:background="#drawable/round_button"-->
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:background="#color/clear"
android:layout_weight="0.15">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="0dp"
android:text="User Name"
android:fontFamily="Roboto-Light"
android:background="#color/clear"/>
<TextView
android:id="#+id/whoRowCompany"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:text="Company"
android:textColor="#color/lightGrey"
android:background="#color/clear"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Thanks
remove this line from your xml view and try:
android:backgroundTint="#color/noteColor"

EditText changes the color into a custom ListView

The following image isn't exactly what I'm developing but can show you the problem.
The EditText out of ListView:
And the same EditText into ListView:
The ListView layout.xml:
<?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:background="#drawable/back_login"
android:padding="20dp"
android:layout_height="match_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/login"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:background="#color/white"
android:drawableLeft="#drawable/ic_txt_user"
android:padding="10dp"
android:drawablePadding="5dp"
android:textColorHint="#CCCCCC"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/password"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:background="#color/white"
android:drawableLeft="#drawable/ic_txt_senha"
android:padding="10dp"
android:drawablePadding="5dp"
android:password="true"
android:textColorHint="#CCCCCC"/>
</LinearLayout>
My ListView:
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
And finally the getView() of my adapter:
#Override
public View getView(int position, View view, ViewGroup viewGroup) {
if (view == null) {
LayoutInflater _layoutInflater = (LayoutInflater) mActivity.getApplicationContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
view = _layoutInflater.inflate(R.layout.activity_login, viewGroup, false);
mHolder = new ViewHolder();
view.setTag(mHolder);
}
else {
mHolder = (ViewHolder) view.getTag();
}
return view;
}
Anyone knows why is this EditText changes the color when I use it into ListView?
After many hours I finally found out the problem. I had to remove getApplicationContext().
The code was such as:
LayoutInflater _layoutInflater = (LayoutInflater) mActivity.getApplicationContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
And now is such as:
LayoutInflater _layoutInflater = (LayoutInflater) mActivity.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);

Set different icons for each row

Above is the main screen of my app with a custom adapter for listview. How do I put a different icon for each row in the listview? I tried putting an ImageView in the xml but it overwrites my whole screen only showing an icon.
MainAcitivty xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/hp_color"
tools:context=".MainActivity" >
<TextView
android:id="#+id/cityText"
style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textSize="28sp" />
<ImageView
android:id="#+id/condIcon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_below="#id/cityText"
android:contentDescription="weather icon" />
<TextView
android:id="#+id/condDescr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/condIcon"
android:textSize="20sp" />
<ListView
android:id="#+id/mainListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<ImageButton
android:id="#+id/btnPicturePage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="picturePage"
android:src="#drawable/photo" />
Custom adapter:
public class WeatherAdapter extends ArrayAdapter<String> {
private final Activity context;
private ArrayList<String> weatherData;
static class ViewHolder {
public TextView text;
public ImageView image;
}
public WeatherAdapter(Activity context, ArrayList<String> weatherData) {
super(context, R.layout.list, weatherData);
this.context = context;
this.weatherData = weatherData;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
// reuse views
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.list, null);
// configure view holder
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) rowView.findViewById(R.id.rowTextView);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
ArrayList<String> s = new ArrayList<String>(weatherData);
String []sa = new String [s.size()];
sa = s.toArray(sa);
holder.text.setText(sa[position]);
if (sa[position].startsWith("Air pressure")) {
rowView.setBackgroundResource(R.color.skyblue) ;
}
return rowView;
}
List xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rowTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:textColor="#color/white" >
</TextView>
Your list.xml should be something similar to this (taken from one my files)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:gravity="center_vertical" android:orientation="horizontal"
android:background="#drawable/xml_pressed_bg" android:clickable="true" android:layout_width="fill_parent"
android:layout_height="54dip"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ttshow="http://schemas.android.com/apk/res-auto">
<ImageView android:id="#+id/imgThumb" android:layout_width="42.0dip" android:layout_height="42.0dip" android:scaleType="fitXY"
android:src="#drawable/sample_dj" />
<TextView android:textSize="14.0sp" android:textColor="#ff666666" android:id="#+id/txtName"
android:layout_width="180dip" android:layout_height="wrap_content"
android:singleLine="true" android:shadowColor="#99ffffff" style="#style/TextShadowLight"
android:text="Hello" android:paddingLeft="10dip"/>
</LinearLayout>
Every row item has an image (imgThumb). This needs to be changed or set to a static image, depending on your needs. This is done in the adapters' getView() method.
imgThumb.setImageResource(R.drawable.my_image);
Private TypedArray img;
img=getResource.obtainTypedArray(R.array.imgIcon)
if (sa[position].startsWith("Air pressure")) {
rowView.setBackgroundResource(R.color.skyblue) ;
holder.image.setImageResource(img.gerResourceId[0]);
}else if (sa[position].startsWith("Air Condition")) {
holder.image.setImageResource(img.gerResourceId[1]);
}

Gridview row height mess up when scrolling

I'm using a gridview to present various article items consisting of two textfield. Because of different amount of text the height of each item is different and a row should be sized with the height of the biggest item of a row. The gridview uses colnum = autofit.
As the following screenshot before and after scrolling show, the behaviour is as expected since i scroll down and up again: Rows mess up and cut content of big items.
What am I missing?
Gridview before scrolling:
GridView after scrolling down and up:
Further code:
item xml code
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="14dp"
android:textColor="#040404"
android:textSize="20sp"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="#343434"
android:textSize="14sp"
android:typeface="serif" />
</LinearLayout>
My ListAdapter (recycles views if possible):
public class SearchResultListViewAdapter extends ArrayAdapter
{
Context context;
Newspaper newspaper;
List<SearchResultListItem> searchResults;
int viewStyle;
public SearchResultListViewAdapter(Context context, int resourceId, List<SearchResultListItem> searchResults, int viewStyle) {
super(context, resourceId, searchResults);
this.context = context;
this.searchResults = searchResults;
this.viewStyle = viewStyle;
}
/* private view holder class */
private class ViewHolder
{
TextView txtTitle;
TextView txtText;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View gridItem;
ViewHolder holder = null;
if (convertView == null)
{
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (this.viewStyle == 0)
{
gridItem = mInflater.inflate(R.layout.searchresult_list_item, null);
} else
{
gridItem = mInflater.inflate(R.layout.searchresult_grid_item, null);
}
holder = new ViewHolder();
} else {
gridItem = convertView;
holder = (ViewHolder) gridItem.getTag();
}
holder.txtText = (TextView) gridItem.findViewById(R.id.text);
holder.txtTitle = (TextView) gridItem.findViewById(R.id.title);
gridItem.setTag(holder);
SearchResultListItem rowItem = getItem(position);
holder.txtText.setText(Html.fromHtml(rowItem.getText()), TextView.BufferType.SPANNABLE);
holder.txtTitle.setText(Html.fromHtml(rowItem.getTitle()), TextView.BufferType.SPANNABLE);
return gridItem;
}
}
And finally my activity layout containing the gridview:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<EditText
android:id="#+id/searchPatternInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/loadSearchResults"
android:imeOptions="actionSearch"
android:inputType="text" />
<ImageButton
android:id="#+id/showExtendedSearch"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_action_filter" />
<ImageButton
android:id="#+id/loadSearchResults"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/showExtendedSearch"
android:src="#drawable/ic_action_search" />
</RelativeLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff" >
<ImageSwitcher
android:id="#+id/nothingLoaded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/ic_nothing_loaded" >
</ImageSwitcher>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" >
<GridView
android:id="#+id/searchResultThumbnailsGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="160dp"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:gravity="center"
android:horizontalSpacing="4dp"
android:listSelector="#drawable/list_selector"
android:numColumns="auto_fit"
android:padding="10dp"
android:layout_weight="1"
android:stretchMode="columnWidth"
android:verticalSpacing="4dp" />
</LinearLayout>
</RelativeLayout>
</TableRow>
</TableLayout>
You seem to have confusion using View.setTag() and View.getTag() methods. Try this:
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder = null;
if (convertView == null)
{
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (this.viewStyle == 0)
{
convertView = mInflater.inflate(R.layout.searchresult_list_item, null);
} else
{
convertView = mInflater.inflate(R.layout.searchresult_grid_item, null);
}
holder = new ViewHolder();
//Always use View.findViewById() and View.setTag() here
holder.txtText = (TextView) convertView.findViewById(R.id.text);
holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(holder);
} else {
//Always use View.getTag() here
holder = (ViewHolder) convertView.getTag();
}
//Always set your data here
SearchResultListItem rowItem = getItem(position);
holder.txtText.setText(Html.fromHtml(rowItem.getText()), TextView.BufferType.SPANNABLE);
holder.txtTitle.setText(Html.fromHtml(rowItem.getTitle()), TextView.BufferType.SPANNABLE);
return convertView;
}
I moved on to use a third party component. The StaggeredGridView workes fine for me, more information can be found here.

Categories

Resources