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>
Related
I am new to Android programming and facing some issues.
I want to achieve this
this is my view on website. I am trying to implement the same on android.
This much is done but I am unable to proceed further and I am stuck with the Button thing. These are the drawers and data is set using Adapter.
My activity_main.xml file
<android.support.v4.widget.DrawerLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context="com.gyanibano.drawerlayout.MainActivity">
<include layout="#layout/app_bar"/>
<ListView
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/drawer_left"
android:divider="#android:color/transparent"
android:layout_gravity="start"
android:layout_width="250dp"
android:layout_height="match_parent"
android:padding="0dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:background="#ffffff">
</ListView>
<ListView
android:layout_marginTop="?attr/actionBarSize"
android:id="#+id/drawer_right"
android:divider="#android:color/transparent"
android:layout_gravity="end"
android:layout_width="250dp"
android:layout_height="match_parent"
android:padding="20dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:background="#ffffff">
</ListView>
</android.support.v4.widget.DrawerLayout>
My gdmainleft.xml file
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="20dp"
android:background="#drawable/border_set"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/sideColor"
android:layout_width="8dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#88FF0000"
android:layout_marginRight="5dp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView1"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/txt"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentRight="true"
android:textColor="#android:color/black"
android:layout_alignTop="#+id/imageView1"
android:layout_toRightOf="#+id/imageView1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<TextView
android:id="#+id/count"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textColor="#android:color/black"
android:textStyle="bold"
android:textSize="26sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
My CustomerAdapter.java file
public class CustomerAdapter extends BaseAdapter {
String result[];
Context context;
String counts[];
int img[], colr[];
int no;
int showquest;
private static LayoutInflater inflater=null;
public CustomerAdapter(String[] result, Context context, String[] counts, int[] img, int colr[], int no, int showquest) {
this.result = result;
this.context = context;
this.counts = counts;
this.img = img;
this.colr = colr;
this.no = no;
this.showquest = showquest;
inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount(){
return result.length;
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
final holder hld = new holder();
View rowview, questview;
if(no==1) {
rowview = inflater.inflate(R.layout.gdmainright, null);
hld.tv = (TextView) rowview.findViewById(R.id.txt);
hld.tv.setText(result[i]);
}
else{
rowview = inflater.inflate(R.layout.gdmainleft, null);
hld.tv = (TextView) rowview.findViewById(R.id.txt);
hld.tv.setText(result[i]);
hld.tv = (TextView) rowview.findViewById(R.id.count);
hld.tv.setText(counts[i]);
hld.tv = (TextView) rowview.findViewById(R.id.sideColor);
hld.tv.setBackgroundColor(colr[i]);
hld.iv = (ImageView) rowview.findViewById(R.id.imageView1);
hld.iv.setImageResource(img[i]);
}
return rowview;
}
public class holder{
TextView tv;
ImageView iv;
Button bt;
}
}
My MainActivity.java file
usercount = jObj.getInt("usercount");
mcqcount = jObj.getInt("mcqcount");
keywordscount = jObj.getInt("keywordscount");
papercount = jObj.getInt("papercount");
showquest = jObj.getInt("showquest");
Tags = " QnA, Tags, Papers, Users";
tagname = Tags.split(",");
Counts = mcqcount+","+keywordscount+","+papercount+","+usercount;
countvalue = Counts.split(",");
Imgs = new int[]{R.drawable.qm, R.drawable.tg, R.drawable.bk, R.drawable.usr};
Colr = new int[]{Color.rgb(255,0,0), Color.rgb(255, 165, 0),Color.rgb(102,204,87), Color.rgb(0,0,255)};
cl3 = new CustomerAdapter(tagname, con, countvalue, Imgs, Colr, 2, showquest);
drawer_left.setAdapter(cl3);
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..
I am trying to create a custom list. My list is contained in a Fragment that correctly implements onScrollListener and populates the list using an adapter. The problem is that I cannot click on each item and I cannot figure out why. Here there is the code of my layout fragment
<?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="#ffffff"
android:clickable="true">
<ListView
android:id="#+id/listNotification"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:paddingStart="15dp"
android:paddingEnd="15dp"
android:clickable="true"
/>
</LinearLayout>
and here there is the code of my custom list
<?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="#ffffff"
android:clickable="true">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/imageNotification"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp"
android:focusable="false"/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:textColor="#33CC33"
android:focusable="false"/>
<TextView
android:id="#+id/idQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:focusable="false"
/>
<TextView
android:id="#+id/typeNotification"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:visibility="gone"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
here there is the code that creates my list using the adapter and setting the onclicklistener
adapter = new NotificationListAdapter(getActivity(), this.rows);
list = (ListView) firstAccessView.findViewById(R.id.listNotification);
list.setAdapter(adapter);
list.setOnScrollListener(this);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(adapter.getItem(position).getTypeNotification()==0) {
mNotificationInteface.readQuestion(adapter.getItem(position).getQuestionId());
}
if(adapter.getItem(position).getTypeNotification()==1){
mNotificationInteface.readAnswer(adapter.getItem(position).getQuestionId());
}
}
});
and here there is the code of my adapter
public class NotificationListAdapter extends ArrayAdapter<NotificationItem> {
private View view;
private final Activity context;
private List<NotificationItem> rows;
private int count = 1;
public NotificationListAdapter(Activity context, List<NotificationItem> firstRows ) {
super(context, R.layout.list_notifications, firstRows);
this.context = context;
this.rows = firstRows;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = context.getLayoutInflater();
view = inflater.inflate(R.layout.list_notifications, null);
view.setPadding(0,10,0,10);
holder = new ViewHolder();
holder.textNotification = (TextView) view.findViewById(R.id.textNotification);
holder.idQuestion = (TextView) view.findViewById(R.id.idQuestion);
holder.typeNotification = (TextView) view.findViewById(R.id.typeNotification);
holder.imageNotification = (ImageView) view.findViewById(R.id.imageNotification);
view.setTag(holder);
} else {
view=convertView;
holder = (ViewHolder) convertView.getTag();
}
int typeNotification = this.rows.get(position).getTypeNotification();
holder.textNotification.setTextColor(Color.BLACK);
holder.idQuestion.setText(String.valueOf(this.rows.get(position).getQuestionId()));
holder.typeNotification.setText(String.valueOf(this.rows.get(position).getTypeNotification()));
if(typeNotification==0){
holder.textNotification.setText(R.string.askQuestion);
holder.imageNotification.setImageResource(R.mipmap.iconuseranonymous);
}
if(typeNotification==1){
//nome da recuperare da con id notifica, quindi id utente quindi dome
holder.textNotification.setText(R.string.answerQuestion);
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").transform(new CircleTransform()).fit().centerCrop().into(holder.imageNotification);
}
if(typeNotification==2){
//nome e immagine da recuperare
holder.textNotification.setText(R.string.newFriend);
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").transform(new CircleTransform()).fit().centerCrop().into(holder.imageNotification);
}
return view;
}
#Override
public NotificationItem getItem(int position){
return this.rows.get(position);
}
#Override
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
static class ViewHolder {
ImageView imageNotification;
TextView textNotification;
TextView idQuestion;
TextView typeNotification;
int position;
}
Remove android:clickable="true" from the ListView and it's parent in your XML layout, and also from the root of your list item layout.
I implemented a custom listView as seen here:
http://www.tutecentral.com/android-custom-navigation-drawer/ but I can't get a correct height for my items in the list. Both header and section layout are way too large (height).
Here is my xml layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/profileLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="0dp"
>
<com.facebook.widget.ProfilePictureView
android:id="#+id/drawer_profilePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
/>
<TextView
android:id="#+id/drawer_profileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="0dp">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<Button
android:id="#+id/button_logout"
android:text="Logout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/sectionLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:minHeight="?android:attr/listPreferredItemHeight"
>
<TextView
android:id="#+id/drawer_sectionName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:layout_marginTop="0dp"
>
<TextView
android:id="#+id/drawer_headerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:background="#DADADC" ></View>
</LinearLayout>
Any suggestion ?
[EDIT] Here is my customDrawerAdapter getview code:
public class CustomDrawerAdapter extends ArrayAdapter<DrawerItem> {
private final JSONObject userProfile;
Context context;
List<DrawerItem> drawerItemList;
int layoutResID;
public CustomDrawerAdapter(Context context, int layoutResourceID,
List<DrawerItem> listItems, JSONObject userProfile) {
super(context, layoutResourceID, listItems);
this.context = context;
this.drawerItemList = listItems;
this.layoutResID = layoutResourceID;
this.userProfile = userProfile;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
DrawerItemHolder drawerHolder;
View view = convertView;
if (view == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
drawerHolder = new DrawerItemHolder();
view = inflater.inflate(layoutResID, parent, false);
drawerHolder.profileName = (TextView) view
.findViewById(R.id.drawer_profileName);
drawerHolder.profilePicture = (ProfilePictureView) view.findViewById(R.id.drawer_profilePicture);
drawerHolder.sectionName = (TextView) view.findViewById(R.id.drawer_sectionName);
drawerHolder.headerName = (TextView) view.findViewById(R.id.drawer_headerName);
drawerHolder.buttonLogout = (Button) view.findViewById(R.id.button_logout);
drawerHolder.buttonLogout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ParseUser.logOut();
Intent intent = new Intent(getContext(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
view.getContext().startActivity(intent);
}
});
drawerHolder.profileLayout = (LinearLayout) view.findViewById(R.id.profileLayout);
drawerHolder.sectionLayout = (LinearLayout) view.findViewById(R.id.sectionLayout);
drawerHolder.headerLayout = (LinearLayout) view.findViewById(R.id.headerLayout);
view.setTag(drawerHolder);
} else {
drawerHolder = (DrawerItemHolder) view.getTag();
}
DrawerItem dItem = this.drawerItemList.get(position);
if (dItem.isHeader()) {
drawerHolder.profileLayout.setVisibility(LinearLayout.INVISIBLE);
drawerHolder.sectionLayout.setVisibility(LinearLayout.INVISIBLE);
drawerHolder.headerLayout.setVisibility(LinearLayout.VISIBLE);
drawerHolder.headerName.setText(dItem.getHeaderName());
} else if (dItem.getProfilePicture() == 0){
drawerHolder.profileLayout.setVisibility(LinearLayout.INVISIBLE);
drawerHolder.sectionLayout.setVisibility(LinearLayout.VISIBLE);
drawerHolder.headerLayout.setVisibility(LinearLayout.INVISIBLE);
drawerHolder.sectionName.setText(dItem.getSectionName());
} else {
drawerHolder.profileLayout.setVisibility(LinearLayout.VISIBLE);
drawerHolder.sectionLayout.setVisibility(LinearLayout.INVISIBLE);
drawerHolder.headerLayout.setVisibility(LinearLayout.INVISIBLE);
try {
if (userProfile.getString("facebookId") != null) {
String facebookId = userProfile.get("facebookId")
.toString();
drawerHolder.profilePicture.setProfileId(facebookId);
} else {
// Show the default, blank user profile picture
drawerHolder.profilePicture.setProfileId(null);
}
if (userProfile.getString("name") != null) {
drawerHolder.profileName.setText(userProfile.getString("name"));
} else {
drawerHolder.profileName.setText("");
}
} catch (JSONException e) {
Log.d(CarpoolMeApp.TAG,
"Error parsing saved user data.");
}
}
return view;
}
You can just set the height manually for both the headerName and the sectionName Textviews
android:layout_height="2dp"
like you did with the View in your headerLayout
You can specify layouts gravities, it is most possible reason of issue (too much height).
Also you can use LinearLayout as root layout instead of RelativeLayout.
If the exact height needed, specify it in the layout_height parameter.
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>