android - GridView is too laggy - android

I use GridView in Fragmnet, Host actvity inlcudes SlidingMenu and My grid Items use simple google now card style. but my gridView is too laggy even i use performance trick for my adapter (recycling and holder pattern).
My Question:
Is there another performance tweak? or Do i follow right way for the performance? (GridView and Adapter)
gridView adapter:
public class CustomGridAdapter extends ArrayAdapter<RbtItem> {
Context context;
int layoutResourceId;
ArrayList<RbtItem> data = new ArrayList<RbtItem>();
public CustomGridAdapter(Context context, int layoutResourceId,
ArrayList<RbtItem> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
RecordHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
holder.imageItem = (ImageView) row.findViewById(R.id.item_image);
row.setTag(holder);
} else {
holder = (RecordHolder) row.getTag();
}
RbtItem item = data.get(position);
holder.txtTitle.setText(item.getText());
holder.imageItem.setImageResource(R.drawable.bg);
return row;
}
static class RecordHolder {
TextView txtTitle;
ImageView imageItem;
}
}
gridView item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="#style/nowCardStyleRaw"
android:layout_width="100dp"
android:layout_height="140dp"
android:orientation="vertical" >
<ImageView
android:id="#+id/item_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/bg" />
<TextView
android:id="#+id/item_text"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:ellipsize="none"
android:gravity="right"
android:maxLines="1"
android:textSize="18sp" />
<TextView
android:id="#+id/item_singer"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="-20dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="5dp"
android:ellipsize="none"
android:gravity="right"
android:maxLines="1"
android:textSize="11sp"
android:textColor="#FF4444" />
</TextView>
fargment layout:
<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_rbt_list_grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e3e3e3"
android:columnWidth="97dp"
android:gravity="center"
android:numColumns="auto_fit"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="8dp"
android:stretchMode="columnWidth"
android:verticalSpacing="12dp" >
</GridView>

Related

issue of scrolling in gridview (specifically in samsung phone)

Hello , I faceing issue in Gridview. and mostly in samsung phone.Sometimes icons are invisible when scrolled or leave lots of space upperside of screen. this all are happened when scroll the menu. please check screenshot.
gridviewadapter.java
public class GridviewAdapter extends ArrayAdapter<HomepageGeSe>
{
Context context;
int layoutResourceId;
ArrayList<HomepageGeSe> data = null;
RecordHolder holder = null;
public GridviewAdapter(Context context, int layoutResourceId, ArrayList<HomepageGeSe> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
static class RecordHolder {
TextView txtTitle;
ImageView imageItem;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.item_text);
holder.imageItem = (ImageView) convertView.findViewById(R.id.item_image);
convertView.setTag(holder);
} else {
holder = (RecordHolder) convertView.getTag();
}
HomepageGeSe list = data.get(position);
holder.txtTitle.setText(list.getName());
if(list.getDrawableId() != 0)
{
holder.txtTitle.setText(list.getName());
Picasso.with(context)
.load(list.getDrawableId())
.fit ()
.error(R.drawable.imagenotavailable)
.into(holder.imageItem);
}
return convertView;
}
}
Homepage.xml
<?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="match_parent"
android:fitsSystemWindows="true"
android:id = "#+id/rootLayout"
android:orientation="vertical">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="1dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:columnWidth="90dp"
android:gravity="center"
android:numColumns="auto_fit"
android:horizontalSpacing="10dp"
android:verticalSpacing="15dp"
android:stretchMode="columnWidth" />
</LinearLayout>
</RelativeLayout>
gridview_row.xml
<?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="match_parent"
android:padding="5dp">
<ImageView
android:id="#+id/item_image"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/imageDes">
</ImageView>
<TextView
android:id="#+id/item_text"
android:layout_below="#+id/item_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:textAppearance="?android:attr/textAppearance"
android:textColor="#color/textview_all">
</TextView>
</RelativeLayout>

Unconditional layout inflation from view adapter

I'm getting a warning like Unconditional layout inflation which is causing the layout to exit and app goes crashing.I need to inflate this layout without crashing.
the crashing is on the following code.
I have the code for the custom adapter set.
public class CustomAdapter extends BaseAdapter {
private List<Response.NodesEntity> mMovieitem;
private Context mContext;
private LayoutInflater inflater;
public CustomAdapter(Context mContext, List<Response.NodesEntity> mMovieitem) {
this.mContext = mContext;
this.mMovieitem = mMovieitem;
}
#Override
public int getCount() {
return mMovieitem.size();
}
#Override
public Object getItem(int position) {
return mMovieitem.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.s, parent, false);
Response.NodesEntity item = (Response.NodesEntity) getItem(position);
ImageView thumbnail = (ImageView) rowView.findViewById(R.id.thumbnail);
TextView title = (TextView) rowView.findViewById(R.id.title);
TextView rating = (TextView) rowView.findViewById(R.id.video_url);
String imageUrl = item.getVideoTumbnail().getSrc();
Picasso.with(mContext).load(imageUrl).into(thumbnail);
title.setText(item.getTitle());
rating.setText(item.getHlsVideo());
return rowView;
}
}
The Xml is in this format . I'm inflating this layout and
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="#+id/video_list"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="info.androidhive.materialdesign.activity.FriendsFragment">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_margin="5dp">
<ImageView
android:id="#+id/thumbnail"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background_material_light"
android:scaleType="centerCrop" />
<TextView
android:layout_marginBottom="10dp"
android:layout_gravity="bottom"
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/thumbnail"
android:layout_toEndOf="#+id/thumbnail"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:typeface="sans"
android:textSize="22sp"
android:textColor="#ffffff" />
<TextView
android:layout_marginTop="20dp"
android:id="#+id/video_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_toEndOf="#+id/thumbnail"
android:layout_toRightOf="#+id/thumbnail"
android:visibility="invisible"/>
</android.support.v7.widget.CardView>
</RelativeLayout>
use View holder method for inflating each rows

How to add a third text view to list view elements using custom list adapter

I followed this tutorial on how to add a header, a text view id/txtTitle, and an image view id/imgIcon to individual list elements within a list view.
I modified the tutorial code to incorporate a third text view id/txtTitle2, however I still only see the image view id/imgIcon and the original text view id/txtTitle. Additionally, the list view seems like it's bigger, or zoomed in. This is the result of my code modifications.
How can I fix the code so I see a the third text view without size distortion?
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
tools:context=".MainActivity">
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
listview_item_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<ImageView android:id="#+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/txtTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="#+id/txtTitle2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
custom list adapter WeatherAdapter extends ArrayAdapter<Weather>
public class WeatherAdapter extends ArrayAdapter<Weather>{
Context context;
int layoutResourceId;
Weather data[] = null;
public WeatherAdapter(Context context, int layoutResourceId, Weather[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
WeatherHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new WeatherHolder();
holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
holder.txtTitle2 = (TextView)row.findViewById(R.id.txtTitle2);
row.setTag(holder);
}
else
{
holder = (WeatherHolder)row.getTag();
}
Weather weather = data[position];
holder.txtTitle2.setText(weather.title2);
holder.txtTitle.setText(weather.title);
holder.imgIcon.setImageResource(weather.icon);
return row;
}
static class WeatherHolder
{
ImageView imgIcon;
TextView txtTitle;
TextView txtTitle2;
}
}
class Weather
public class Weather {
public int icon;
public String title;
public String title2;
public Weather(){
super();
}
public Weather(int icon, String title, String title2) {
super();
this.icon = icon;
this.title = title;
this.title2 = title2;
}
}
In your row layout both your 2nd and 3rd text views have a width set as fill _ parent.. so in this scenario, the 2nd TextView takes up the entire width of the screen, and the 3rd TextView has no space left.. just change those attributes to wrap_content, or use weights instead..

NullPointerException at addHeaderView and setAdapter

Note : i have refered similar questions and still cannot find any mistakes
NullPointerException at
listView.addHeaderView(header);
AND
listView.setAdapter(adapter);
detailed code :
Veg v = new Veg();
v.setId(1);
v.setName("some");
v.setPrice(15.0);
List<Veg> vegData = new ArrayList<Veg>();
// dummy add for testing
vegData.add(v);
vegData.add(v);
vegData.add(v);
CustomAdapter adapter = new CustomAdapter(this,
R.layout.custom_list_rows, vegData);
listView = (ListView) findViewById(R.id.listView1);
View header = getLayoutInflater().inflate(
R.layout.custom_list_header, null);
listView.addHeaderView(header);
listView.setAdapter(adapter);
getView() part
public class CustomAdapter extends ArrayAdapter<Veg> {
Context context;
int layoutResourceId;
List<Veg> data;
public CustomAdapter(Context context, int resource, List<Veg> data) {
super(context, resource);
this.context = context;
this.layoutResourceId = resource;
this.data = data;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
CustomHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new CustomHolder();
holder.at = (TextView) row.findViewById(R.id.customheaderbutton1);
holder.bt = (TextView) row.findViewById(R.id.customheaderbutton2);
holder.ct = (TextView) row.findViewById(R.id.customheaderbutton3);
row.setTag(holder);
} else {
holder = (CustomHolder) row.getTag();
}
holder.at.setText(String.valueOf(data.get(position).getId()));
holder.bt.setText(data.get(position).getName());
holder.ct.setText(String.valueOf(data.get(position).getPrice()));
return row;
}
static class CustomHolder {
TextView at;
TextView bt;
TextView ct;
}
}
main activity xml file
<?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:background="#FFFFFF">
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
custom_list_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:id="#+id/customheaderbutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:text="marketname" />
<Button
android:id="#+id/customheaderbutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:text="edit" />
<Button
android:id="#+id/customheaderbutton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:text="+" />
</LinearLayout>
custom_list_rows.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/elementIDtext"
android:layout_width="11dp"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/elementName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.30"
android:text="#string/elementName"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/elementSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/elementValue"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="62dp"
android:layout_height="wrap_content"
android:text="#string/_" />
</LinearLayout>
Sounds like listView is null, which means findViewById() returned null: it couldn't find the control you're looking for. Without seeing your layout there's no way to debug further, but look to be sure R.id.listView1 refers to a valid element.
In getView, change
holder.at = (TextView) row.findViewById(R.id.customheaderbutton1);
holder.bt = (TextView) row.findViewById(R.id.customheaderbutton2);
holder.ct = (TextView) row.findViewById(R.id.customheaderbutton3);
to
holder.at = (TextView) row.findViewById(R.id.elementIDtext);
holder.bt = (TextView) row.findViewById(R.id.elementName);
holder.ct = (TextView) row.findViewById(R.id.elementSummary);
Replace your Code With Below:
package com.example.listview;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class List extends Activity
{
private ListView listview;
Veg Veg = new Veg();
ArrayList<Veg> data = new ArrayList<Veg>();
CustomAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
listview = (ListView)findViewById(R.id.listView);
for(int i=1;i<101;i++)
{
Veg = new Veg();
Veg.setName("Item "+i);
Veg.setID("ID "+i);
Veg.setPrice("Price "+i);
data.add(Veg);
}
View headerView = getLayoutInflater().inflate(
R.layout.custom_list_header, null);
listview.addHeaderView(headerView);
adapter = new CustomAdapter(this,R.layout.custom_list_rows,data);
listview.setAdapter(adapter);
}
class CustomAdapter extends ArrayAdapter<Veg>
{
Context con;
int Res;
ArrayList<Veg> data;
public CustomAdapter(Context context, int resource, ArrayList<Veg> data) {
super(context, resource,data);
// TODO Auto-generated constructor stub
con = context;
Res = resource;
this.data = data;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
CustomHolder holder = null;
if (row == null) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(Res, parent, false);
holder = new CustomHolder();
holder.at = (TextView) row.findViewById(R.id.elementIDtext);
holder.bt = (TextView) row.findViewById(R.id.elementName);
holder.ct = (TextView) row.findViewById(R.id.elementSummary);
row.setTag(holder);
} else {
holder = (CustomHolder) row.getTag();
}
holder.at.setText(String.valueOf(data.get(position).getID()));
holder.bt.setText(data.get(position).getName());
holder.ct.setText(String.valueOf(data.get(position).getPrice()));
return row;
}
class CustomHolder {
TextView at;
TextView bt;
TextView ct;
}
}
}
Also You have to Change your XML Something Like below instead giving Static Width like 11 dp.
custom_list_rows.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/elementIDtext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ID"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/elementName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="elementName"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/elementSummary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="elementValue"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="btn" />
</LinearLayout>

RelativeLayout Buttons on top and custom listview below buttons

I've searched but not found any examples for what I want to do. I'm sure its trivial but I'm stumped. I have a custom listview adapter and a defined relative layout. The entire layout is being called for each item, I want my buttons to only appear once on top. Any advice would be greatly appreciated.
This is how it looks now:
http://img440.imageshack.us/img440/2803/device20120104173817.png
This is how I want it to look:
http://img215.imageshack.us/img215/805/devicewant.png
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/relativeLayout2">
<TextView
android:id="#+id/postinfo"
android:layout_below="#+id/FirstPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
<TextView
android:id="#+id/dateinfo"
android:layout_alignRight="#+id/postinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
<TextView
android:id="#+id/post"
android:layout_below="#+id/postinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
<ImageView
android:id="#+id/icon2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/post"
android:contentDescription="OCForums thread icon"
android:focusable="false"
/>
<RelativeLayout
android:id="#+id/relativeLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top" >
<Button
android:id="#+id/LastPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/last" />
<Button
android:id="#+id/NextPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/LastPage"
android:text="#string/next" />
<Button
android:id="#+id/FirstPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/first" />
<Button
android:id="#+id/PreviousPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/FirstPage"
android:text="#string/previous" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
static class MyCustomAdapter2 extends BaseAdapter {
private LayoutInflater mInflater;
public MyCustomAdapter2(Context context, int textViewResourceId,List<List<String>> objects) {
super();
mInflater = LayoutInflater.from(context);
rid = textViewResourceId;
fcontext = context;
usernames = objects.get(0);
usernamecolors = objects.get(1);
dates = objects.get(2);
messages = objects.get(3);
Log.i("is it empy?(messages)",Integer.toString(messages.size()));
Log.i("is it empy?(dates)",Integer.toString(dates.size()));
Log.i("is it empy?(usernamecolors)",Integer.toString(usernamecolors.size()));
Log.i("is it empy?(usernames)",Integer.toString(usernames.size()));
}
public int getCount() {
return lists.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(rid, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.postinfo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(usernames.get(position));
holder.text.setTextColor(Color.parseColor(usernamecolors.get(position)));
ViewHolder holderd;
if (convertView == null) {
convertView = mInflater.inflate(rid, null);
holderd = new ViewHolder();
holderd.text = (TextView) convertView.findViewById(R.id.dateinfo);
convertView.setTag(holderd);
} else {
holderd = (ViewHolder) convertView.getTag();
}
holderd.text.setText(dates.get(position));
ViewHolder holderm;
if (convertView == null) {
convertView = mInflater.inflate(rid, null);
holderm = new ViewHolder();
holderm.text = (TextView) convertView.findViewById(R.id.post);
convertView.setTag(holderm);
} else {
holderm = (ViewHolder) convertView.getTag();
}
holderm.text.setText(messages.get(position));
ImageView icon=(ImageView)convertView.findViewById(R.id.icon2);
if (newlist.size() > 0 && lists.get(position).matches(newlist.get(position))){
icon.setImageResource(R.drawable.forum_new);
}
else{
icon.setImageResource(R.drawable.forum_old);
}
return convertView;
}
static class ViewHolder {
TextView text;
}
}
This is where I am calling it all.
ListView listview = (ListView) findViewById(R.id.listView3);
listview.setAdapter(new CustomListView.MyCustomAdapter2(ThreadActivity.this, R.layout.row2, output));
You need to define the header as a separate layout (separate xml file) then instantiate it and add it to the listview as a header -- then this layout will show as the first item in the list.
See this question: Android ListView with complex header

Categories

Resources