Adapter and Dynamic data in Drawer - android

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);

Related

grid view items not scrolling down to up (repeating the items) and when i am loading data from server in android?

I have a grid view and data updated in grid view using api calls and grid item loads a image from url using picasso library all are perfect but when i am scrolling down to up the grid items not scrolled and repeating the items(up to down scrolling was perfect).
Adapterclass.java
private class ProductAdapter extends BaseAdapter {
ViewHolder holder = null;
#Override
public int getCount() {
return mProducts != null ? mProducts.size() : 0;
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
holder = new ViewHolder();
if (convertView == null) {
// convertView = LayoutInflater.from(Products_activity.this).inflate(R.layout.product_layout, null, false);
LayoutInflater vi = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.product_layout, null);
holder.product_name = (TextView) convertView.findViewById(R.id.product_name);
holder.product_descr = (TextView) convertView.findViewById(R.id.product_desc);
holder.product_price = (TextView) convertView.findViewById(R.id.product_price);
holder.product_pic = (ImageView) convertView.findViewById(R.id.iv_division_img);
holder.product_share = (ImageView) convertView.findViewById(R.id.productshare_button);
holder.like_image=(ImageView) convertView.findViewById(R.id.like_image);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
if (mProducts != null) {
String url = "http://staggershop.pivalue.net/assets/product_images/"+mProducts.get(position).product_image;
String urls = url.replaceAll(" ", "%20");
Picasso.with(getApplicationContext()).load(urls).resize(300,300).noFade().error(R.drawable.home_brands).into(holder.product_pic);
holder.product_name.setText(mProducts.get(position).product_name);
//product_descr.setText(mProducts.get(position).pr);
// product_price.setText(mProducts.get(position).product_price);
/* Picasso
.with(getApplicationContext())
.setLoggingEnabled(true);
Picasso.with(getApplicationContext())
.load(urls)
.error(R.drawable.home_brands).memoryPolicy(MemoryPolicy.NO_STORE)
.networkPolicy(NetworkPolicy.NO_STORE)
.into(product_pic);*/
holder.product_descr.setText(mProducts.get(position).product_description);
if(!recently_beans.isEmpty()){
for(int i=0;i<recently_beans.size();i++) {
if (mProducts.get(position).prdid.equals(recently_beans.get(i).prod_id))
{
holder.like_image.setImageResource(R.drawable.like);
}
}
notifyDataSetChanged();
}
}
holder.product_share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BottomSheetFragment bottomSheetFragment = new BottomSheetFragment();
bottomSheetFragment.show(getSupportFragmentManager(), bottomSheetFragment.getTag());
}
});
holder.like_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
if (!recently_beans.isEmpty()) {
for (int i = 0; i < recently_beans.size(); i++) {
if (mProducts.get(position).prdid.equals(recently_beans.get(i).prod_id)) {
holder.like_image.setImageResource(R.drawable.dislike);
Inserfavorite(mProducts.get(position).prdid);
}
}
}
}
});
}
});
// notifyDataSetChanged();
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Inserrecent(mProducts.get(position).prdid);
Intent intent = new Intent(Products_activity.this, Product_description.class);
startActivity(intent);
}
});
return convertView;
}
}
public static class ViewHolder {
public TextView product_name;
public TextView product_descr;
public TextView product_price;
public ImageView product_pic ;
public ImageView product_share;
public ImageView like_image;
}
This my product.xml
<RelativeLayout
android:id="#+id/rl_divisioin_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/product_img">
<ImageView
android:id="#+id/iv_division_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/view"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:src="#drawable/home_brands" />
</LinearLayout>
<LinearLayout
android:id="#+id/prod_name_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/product_img"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="4dp"
android:fontFamily="#string/font_family_regular"
android:gravity="center"
android:padding="5dp"
android:maxLines="1"
android:text="product name"
android:textColor="#color/black"
android:textSize="10sp" />
<TextView
android:id="#+id/product_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="4dp"
android:fontFamily="#string/font_family_regular"
android:gravity="center"
android:maxLines="1"
android:padding="5dp"
android:text="product Description"
android:textColor="#color/black"
android:textSize="10sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/product_desc"
android:layout_gravity="center"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/product_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:elevation="4dp"
android:text="100$"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/productshare_button"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:elevation="4dp"
android:layout_marginRight="5dp"
android:src="#mipmap/symbol_dotss"
android:text="product name"
android:textColor="#color/black"
android:textSize="10sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="5dp"
android:id="#+id/like_image"
android:layout_alignParentEnd="true"
android:src="#drawable/dislike" />
</RelativeLayout>
activty_product.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/rltool"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar1"
android:background="#color/textColorPrimary"
app:titleTextColor="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/AppTheme.Toolbar"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/search1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/background_shape_buttons">
<!-- <EditText
android:id="#+id/searchEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#D6D5C0"
android:hint="Search..................."
android:layout_gravity="center"
android:backgroundTint="#00000000" />-->
<SearchView
android:id="#+id/search"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textColorHint="#D6D5C0"
android:text="#string/search"
android:layout_gravity="center"
android:iconifiedByDefault="false">
<requestFocus />
</SearchView>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<View
android:id="#+id/shadow_view"
android:layout_width="match_parent"
android:layout_alignBottom="#+id/toolbar1"
android:visibility="visible"
android:layout_height="3dp"
android:background="#drawable/toolbar_shadow" />
</RelativeLayout>
<GridView
android:id="#+id/product_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scrollbars="vertical"
android:layout_margin="15dp"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:verticalSpacing="10dp">
</GridView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
To avoid the unexpected behaviour , provide the implementations of
#Override
public Object getItem(int position) {
return mProducts.get(position);
}
#Override
public long getItemId(int position) {
//return position; or better to provide some unique id
// as there is one in your code, product id
return mProducts.get(position).prod_id;
}
Note : remove notifyDataSetChanged(); in getView because it will trigger the adapter to refresh all view while they are under creating which can cause this behaviour.
Recommended Read
What is the intent of the methods getItem and getItemId in the Android class BaseAdapter?

With upcoming message chat layout doesn't move above with message rather than message get shift to another direction

Chat_thread.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="left"
android:paddingLeft="10dp"
android:paddingRight="50dp">
<!-- For self message -->
<LinearLayout
android:background="#drawable/balloon_incoming_normal"
android:elevation="2dp"
android:layout_margin="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:padding="8dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_marginLeft="10dp"
android:id="#+id/textViewMessage"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello how are you?" />
<TextView
android:layout_marginLeft="10dp"
android:id="#+id/textViewTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Belal Khan, 2016-05-29 16:02:00?"
android:textSize="10dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
**Chat_other_thread.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="wrap_content"
android:orientation="vertical"
android:gravity="right"
android:paddingRight="10dp"
android:paddingLeft="50dp">
<LinearLayout
android:background="#drawable/balloon_outgoing_normal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="2dp"
android:orientation="vertical"
android:padding="8dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="3dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_marginRight="10dp"
android:id="#+id/textViewMessage"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello how are you?" />
<TextView
android:layout_marginRight="10dp"
android:id="#+id/textViewTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="10dp"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
**Demo_chat.xml**
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/list_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activity.MainActivity" >
<LinearLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:background="#color/colorPrimary"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/back_white"
android:layout_marginRight="10dp"
/>
<LinearLayout
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/black_mix"
android:layout_marginRight="10dp"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.5"
>
<TextView
android:id="#+id/chat_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Kamal Jain"
android:textSize="20dp"
android:textColor="#fff"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Last seen 2 days ago"
android:textColor="#b6dbe5"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="7dp"
android:layout_height="7dp"
android:background="#drawable/white_no_border"
android:orientation="vertical"
>
</LinearLayout>
<LinearLayout
android:layout_width="7dp"
android:layout_height="7dp"
android:background="#drawable/white_no_border"
android:orientation="vertical"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
>
</LinearLayout>
<LinearLayout
android:layout_width="7dp"
android:layout_height="7dp"
android:background="#drawable/white_no_border"
android:orientation="vertical"
>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!--main title end here-->
<ListView
android:id="#+id/chat_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.00"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:divider="#null"
android:dividerHeight="5dp"/>
<include
android:id="#+id/footer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/footer" />
<LinearLayout
android:orientation="horizontal"
android:id="#+id/footer_for_emoticons"
android:layout_width="match_parent"
android:layout_height="#dimen/keyboard_height"
android:background="#android:color/transparent"
android:visibility="gone" />
</LinearLayout>
GroupChatListAdapter.class
package com.trackliy.trackliy.messanger;
/**
* Created by cbr on 3/24/2017.
*/
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import android.content.Context;
import android.text.SpannableString;
import android.text.Spanned;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.trackliy.trackliy.R;
import com.trackliy.trackliy.Session;
import com.trackliy.trackliy.model.GroupMessageModel;
import com.trackliy.trackliy.model.Message;
public class GroupChatListAdapter extends BaseAdapter {
private ArrayList<Spanned> comments;
private Context mContext;
private LayoutInflater inflater;
private Session session;
//Tag for tracking self message
private final int Comment_Log_In_User = 0;
private final int Comment_Other_User = 1;
//ArrayList of messages object containing all the messages in the thread
private ArrayList<GroupMessageModel> groupMessagesList;
// public ChatListAdapter(Context context, ArrayList<Spanned> comments,String users) {
//Constructor
public GroupChatListAdapter(Context context, ArrayList<GroupMessageModel> groupMessages) {
this.mContext = context;
this.groupMessagesList = groupMessages;
session = new Session(context);
this.comments = comments;
this.inflater = LayoutInflater.from(context);
}
public void addGroupMessage(GroupMessageModel m) {
groupMessagesList.add(m);
notifyDataSetChanged();
}
public void addGroupMessageList(ArrayList<GroupMessageModel> groupMessagesList) {
this.groupMessagesList.addAll(groupMessagesList);
Log.d("Addmessage",groupMessagesList.toString());
notifyDataSetChanged();
}
#Override
public int getItemViewType(int position) {
//getting message object of current position
GroupMessageModel message = groupMessagesList.get(position);
// Here you have to write logic for which position have which type of row and return the same
if (message.getUserid().equals( session.get_id())) {
return Comment_Log_In_User;
} else if (!message.getUserid().equals(session.get_id()) ) {
//Returning other user
return Comment_Other_User;
}
//else returning position
return position;
}
public View getView(final int position, View view, ViewGroup parent) {
ViewHolder holder = null;
// View v = convertView;
if (getItemViewType(position) == Comment_Log_In_User) {
if (view == null) {
view = inflater.inflate(R.layout.chat_thread, parent, false);//set layout for displaying items
holder = new ViewHolder();
holder.textViewMessage = (TextView) view.findViewById(R.id.textViewMessage);
holder.textViewTime = (TextView) view.findViewById(R.id.textViewTime);
// holder.reciever_UserName=(TextView)view.findViewById(R.id.chat_user_name);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
GroupMessageModel message = groupMessagesList.get(position);
SpannableString spannedTxt = new SpannableString(message.getMessage());
holder.textViewMessage.setText(spannedTxt);
//holder.textViewTime.setText(message.getTime_stamp());
String formatedDate = convertTimeStampIntoFormat(String.valueOf(message.getTime_stamp()));
holder.textViewTime.setText(formatedDate);
} else if (getItemViewType(position) == Comment_Other_User) {
if (view == null) {
view = inflater.inflate(R.layout.chat_thread_other,parent, false);//set layout for displaying items
holder = new ViewHolder();
holder.textViewMessage = (TextView) view.findViewById(R.id.textViewMessage);
holder.textViewTime = (TextView) view.findViewById(R.id.textViewTime);
// holder.reciever_UserName=(TextView)view.findViewById(R.id.chat_user_name);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
GroupMessageModel message = groupMessagesList.get(position);
holder.textViewMessage.setText(message.getMessage());
holder.textViewTime.setText(message.getName());
String formatedDate = convertTimeStampIntoFormat(String.valueOf(message.getTime_stamp()));
holder.textViewTime.setText(formatedDate);
}
// final Spanned item = comments.get(position);
/*TextView fans_image = (TextView) v.findViewById(R.id.item_text);
fans_image.setText(item);*/
return view;
}
#Override
public int getCount() {
return groupMessagesList.size();
}
#Override
public Object getItem(int position) {
return groupMessagesList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
private String convertTimeStampIntoFormat(String time_stamp) {
SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
String finalDate = "";
if (time_stamp.contains(".")) {
time_stamp = time_stamp.substring(0, time_stamp.indexOf('.'));
}
try {
finalDate = sdf1.format(sdf2.parse(time_stamp));
} catch (Exception e) {
e.printStackTrace();
}
return finalDate;
}
public class ViewHolder {
public TextView textViewMessage;
public TextView textViewTime;
public TextView reciever_UserName;
}
}
Whenever I send or fetch a new message, the layout of the message doesn't shift with the message rather than message get shift in other direction.
i.e left to right but it should move on the same direction.
Please tell me what I'm missing.

Android - update ListView in onCreate does not work

I have the following code:
public class MainActivity extends Activity {
private ListView list;
private static final String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "BOE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.listView1);
String books[] = {"Mercedes", "Skoda", "Volkswagen", "Audi", "Citroen", "plik"};
BookArrayAdapter bma = new BookArrayAdapter(this, books);
bma.setNotifyOnChange(true);
list.setAdapter(bma);
if (!new File(path).exists()) {
new File(path).mkdirs();
}
for (int i=0; i<books.length; i++) {
View v = list.getAdapter().getView(i, null, null);
String name = ((TextView)v.findViewById(R.id.row_text)).getText() + "";
for (File f:new File(path).listFiles()) {
if (f.isFile()) {
Button b = (Button) v.findViewById(R.id.row_button);
if (name.equals(f.getName().substring(0, f.getName().length()-4))) {
b.setText("Open");
} else {
b.setText("Download");
}
bma.notifyDataSetInvalidated();
bma.notifyDataSetChanged();
Log.d("AC", b.getText().toString());
}
}
}
}
public class BookArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public BookArrayAdapter(Context context, String[] values) {
super(context, R.layout.row, values);
this.context = context;
this.values = values;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.row, parent, false);
final TextView textView = (TextView) rowView.findViewById(R.id.row_text);
textView.setText(values[position]);
rowView.findViewById(R.id.row_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (((Button)v).getText().toString().equals("Open")) {
//open
} else {
//Download
}
}
});
return rowView;
}
}
}
and I have problems in for loop in onCreate. this Log shows correct Download/Open texts depenging on Files in file system. But the graphical representation of this list view does not changing. Here's my layout.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"
tools:context="${relativePackage}.${activityClass}" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</ListView>
<RelativeLayout
android:id="#+id/main_linear_blackout"
android:layout_width="match_parent"
android:visibility="invisible"
android:layout_height="match_parent"
android:background="#CC000000" >
<ProgressBar
android:id="#+id/main_progress_startup"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</RelativeLayout>
and my row.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/row_button"
android:orientation="vertical" >
<TextView
android:id="#+id/row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar
android:id="#+id/row_progress"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="invisible" />
</LinearLayout>
<Button
android:id="#+id/row_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/row_percentage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/row_button"
android:layout_alignBottom="#+id/row_button"
android:layout_alignLeft="#+id/row_button"
android:layout_alignRight="#+id/row_button"
android:layout_alignTop="#+id/row_button"
android:gravity="center"
android:textAlignment="center"
android:textSize="20sp"
android:visibility="invisible" />
</RelativeLayout>
how to update it? What is wrong?
EDIT:
I moved editing single row to getView(...) overrided method on my adapter class. I don't really know why my first idea was wrong, but now it works.

ListView row containing another ListView

I am using ListView inside the row of another ListView. In wishlist.xml, I have one ListView. That items were in wishlist_items.xml, In that wishlist_items also having one more listView. that was designed in wishlist_items_advisors.xml. My problem is that send ListView is showing only one item. Can any one tell me how to fix this?
And the adapters also given below.
wishlist.xml
<LinearLayout
android:id="#+id/logo_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:contentDescription="#string/app_name" />
<LinearLayout
android:id="#+id/title_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/titleredbg"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/wishlist_title"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<Button
android:id="#+id/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
<Button
android:id="#+id/add_person"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name"
android:padding="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="57"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/wishlist_name_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="40"
android:text="#string/wishlist_name"
android:textColor="#color/Black" />
<TextView
android:id="#+id/wishlist_email_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:text="#string/wishlist_email"
android:textColor="#color/Black" />
</LinearLayout>
<TextView
android:id="#+id/wishlist_relation_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="43"
android:text="#string/wishlist_relation"
android:textColor="#color/Black" />
</LinearLayout>
<LinearLayout
android:id="#+id/items_footer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:weightSum="100" >
<ListView
android:id="#+id/listView_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="4dp"
android:visibility="visible" >
</ListView>
<LinearLayout
android:id="#+id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/no_data"
android:textColor="#000" >
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
wishlist_items.xml
<TextView
android:id="#+id/hr1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:background="#D2D2D2" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="57"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/wishlist_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="40"
android:ellipsize="end"
android:maxLines="2"
android:text="John John John John John John"
android:textColor="#color/Black" />
<TextView
android:id="#+id/wishlist_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:ellipsize="end"
android:maxLines="2"
android:text="krishna.mondeddu#gmail.com krishna.mondeddu#gmail.com"
android:textColor="#color/Black" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="43"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/wishlist_relation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="60"
android:ellipsize="end"
android:maxLines="2"
android:text="Birthday Birthday vv Birthday Birthday"
android:textColor="#color/Black" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="40" >
<ImageButton
android:id="#+id/editButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/deleteButton"
android:background="#drawable/wishlistediticon"
android:contentDescription="#string/app_name" />
<ImageButton
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/hr4"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#D2D2D2" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<TextView
android:id="#+id/gift_advisor_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/wishlist_getadvisor"
android:textColor="#color/Black" />
</LinearLayout>
<TextView
android:id="#+id/hr1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#D2D2D2" />
<ListView android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
></ListView>
<TextView
android:id="#+id/hr5"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#D2D2D2" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#fff"
android:paddingTop="5dp"
android:paddingBottom="5dp"
>
<ImageButton
android:id="#+id/invite_advisor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</LinearLayout>
wishlist_items_advisors.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:weightSum="100" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="57"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/advisor_name_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="40"
android:ellipsize="end"
android:maxLines="2"
android:text="John John"
android:textColor="#color/Black" />
<TextView
android:id="#+id/advisor_email_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="60"
android:ellipsize="end"
android:maxLines="2"
android:text="krishna."
android:textColor="#color/Black" />
</LinearLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="43" >
<TextView
android:id="#+id/status_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/deleteButton"
android:text="Accept" />
<ImageButton
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</LinearLayout>
CustomAdapter
public class CustomAdapter extends BaseAdapter{
private String guestIds[]=null;
private String names[]=null;
private String emails[] = null;
private String relationships[] = null;
private String occasions[] = null;
DisplayImageOptions doption=null;
private ImageLoadingListener animateFirstListener =null;
private Context context=null;
public CustomAdapter(Activity activity,String[] guestId,String[] name,String[] email,String[] relationship, String[] occasion)
{
this.context=activity;
this.guestIds = guestId;
this.names =name;
this.emails = email;
this.relationships = relationship;
this.occasions = occasion;
doption=new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty).showImageOnFail(R.drawable.ic_error).showStubImage(R.drawable.ic_stub).cacheInMemory(true).cacheOnDisc(true).displayer(new RoundedBitmapDisplayer(5)).build();
animateFirstListener = new AnimateFirstDisplayListener();
}
#Override
public int getViewTypeCount() {
return 2;
}
#Override
public int getItemViewType(int position) {
//CustomAdapter item = (CustomAdapter) getItem(position);
if (isItemAnAd(position)) {
return 0;
} else {
return 1;
}
}
private boolean isItemAnAd(int position) {
// Place an ad at the first
return (position == 0);
}
#Override
public Object getItem(int arg0) {
return arg0;
}
#Override
public long getItemId(int arg0) {
return arg0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
if (convertView == null) {
view = ((Activity) context).getLayoutInflater().inflate(R.layout.wishlist_items, parent, false);
holder = new ViewHolder();
holder.wishlistName = (TextView) view.findViewById(R.id.wishlist_name);
holder.wishlistEmail = (TextView) view.findViewById(R.id.wishlist_email);
holder.wishlistRelation = (TextView) view.findViewById(R.id.wishlist_relation);
holder.wishGiftAdvisorText = (TextView) view.findViewById(R.id.gift_advisor_text);
holder.advisorListview = (ListView) view.findViewById(R.id.listView);
holder.inviteAdvisor = (ImageButton) view.findViewById(R.id.invite_advisor);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.wishlistName.setText(names[position]);
holder.wishlistEmail.setText(emails[position]);
holder.wishlistRelation.setText(relationships[position]);
holder.wishGiftAdvisorText.setText(getResources().getString( R.string.wishlist_getadvisor)+" "+names[position]+"'s "+getResources().getString( R.string.wishlist_title) );
GuestId = guestIds[position];
holder.wishlistName.setTypeface(tf);
holder.wishlistEmail.setTypeface(tf);
holder.wishlistRelation.setTypeface(tf);
holder.wishGiftAdvisorText.setTypeface(tf);
if(occasions[position].contains("[")) {
try {
array = new JSONArray(occasions[position]);
System.out.println(array.toString(2));
//loadOccasionData(array);
// TODO Auto-generated method stub
if(array!= null) {
advisorIds = new String[array.length()];
advisorNames = new String[array.length()];
advisorEmails = new String[array.length()];
advisorRelationships = new String[array.length()];
advisorStatuses = new String[array.length()];
for (int i = 0; i < array.length(); i++) {
JSONObject c;
try {
c = array.getJSONObject(i);
// Storing each json item in variable
advisorIds[i] = c.getString("advisor_id");
advisorNames[i] = c.getString("name");
advisorEmails[i] = c.getString("email");
advisorRelationships[i] = c.getString("relationship");
advisorStatuses[i] = c.getString("status");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
CustomAdvisorAdapter adapter = new CustomAdvisorAdapter(WishList.this,
advisorIds, advisorNames, advisorEmails, advisorRelationships , advisorStatuses);
holder.advisorListview.setAdapter(adapter);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
holder.advisorListview.setAdapter(null);
}
return view;
}
private class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
}
private class ViewHolder {
public TextView wishlistName;
public TextView wishlistEmail;
public TextView wishlistRelation;
public TextView wishGiftAdvisorText;
public ListView advisorListview;
public ImageButton inviteAdvisor;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return names.length;
}
}
CustomAdvisorAdapter
public class CustomAdvisorAdapter extends BaseAdapter{
private String advisorIds[]=null;
private String advisorNames[]=null;
private String advisorEmails[] = null;
private String advisorRelationships[] = null;
private String advisorStatuses[] = null;
DisplayImageOptions doption=null;
private ImageLoadingListener animateFirstListener =null;
private Context context=null;
public CustomAdvisorAdapter(Activity activity,String[] advisorId,String[] advisorName,String[] advisorEmail,String[] advisorRelationship, String[] advisorStatus)
{
this.context=activity;
this.advisorIds = advisorId;
this.advisorNames =advisorName;
this.advisorEmails = advisorEmail;
this.advisorRelationships = advisorRelationship;
this.advisorStatuses = advisorStatus;
doption=new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty).showImageOnFail(R.drawable.ic_error).showStubImage(R.drawable.ic_stub).cacheInMemory(true).cacheOnDisc(true).displayer(new RoundedBitmapDisplayer(5)).build();
animateFirstListener = new AnimateFirstDisplayListener();
}
#Override
public Object getItem(int arg0) {
return arg0;
}
#Override
public long getItemId(int arg0) {
return arg0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View viewAdvisor = convertView;
final ViewHolder advisorHolder;
if (convertView == null) {
viewAdvisor = ((Activity) context).getLayoutInflater().inflate(R.layout.wishlist_items_advisor, parent, false);
advisorHolder = new ViewHolder();
advisorHolder.advisorNameText = (TextView) viewAdvisor.findViewById(R.id.advisor_name_text);
advisorHolder.advisorEmailText = (TextView) viewAdvisor.findViewById(R.id.advisor_email_text);
advisorHolder.statusText = (TextView) viewAdvisor.findViewById(R.id.status_text);
viewAdvisor.setTag(advisorHolder);
} else {
advisorHolder = (ViewHolder) viewAdvisor.getTag();
}
advisorHolder.advisorNameText.setText(advisorNames[position]);
advisorHolder.advisorEmailText.setText(advisorEmails[position]);
advisorHolder.statusText.setText(advisorStatuses[position]);
advisorHolder.advisorNameText.setTypeface(tf);
advisorHolder.advisorEmailText.setTypeface(tf);
advisorHolder.statusText.setTypeface(tf);
return viewAdvisor;
}
private class AnimateFirstDisplayListener extends SimpleImageLoadingListener {
final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
}
private class ViewHolder {
public TextView advisorNameText;
public TextView advisorEmailText;
public TextView statusText;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return names.length;
}
}
It's not possible to make a scrollable view inside a scrollable view. But as a work around this, and only in case that this listviews doesn't take much memory if all views are loaded.
you can use this
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
public class NonScrollableListView extends ListView {
public NonScrollableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Do not use the highest two bits of Integer.MAX_VALUE because they are
// reserved for the MeasureSpec mode
int heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightSpec);
getLayoutParams().height = getMeasuredHeight();
}
}
Again, it's not good to use this workaround
you will use this non Scrollable listview in the child.xml layout by adding it as a customized UI component
<LinearLayout 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:orientation="vertical" >
<com.youpackage.uiutils.NonScrollableListView
android:id="#+id/non_scrollable_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
You can ExpandableListView in place of making custom view also for data handling you can use ExpandableListAdapter.

Android GridView issue when scrolling

I'm using a GridView. Everything loads fine. But when scrolling content inside some of the items shifts to the baseline. But when touched it goes to the top again. It's a crazy bug.
Activity Xml
enter code here
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".HomeActivity" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include layout="#layout/color_bar" />
<RelativeLayout
style="#style/default_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_color_bar" >
<RelativeLayout
android:id="#+id/rl_top_icons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<Button
android:id="#+id/btn_ctp_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/btn_ctp_selector" />
<Button
android:id="#+id/btn_twitter"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/btn_facebook"
android:background="#drawable/btn_twitter_selector" />
<Button
android:id="#+id/btn_facebook"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/btn_youtube"
android:background="#drawable/btn_facebook_selector" />
<Button
android:id="#+id/btn_youtube"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/btn_linked_in"
android:background="#drawable/btn_youtube_selector" />
<Button
android:id="#+id/btn_linked_in"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/btn_twitter_selector" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_top_icons">
<GridView
android:id="#+id/grid_properties"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="auto_fit"
android:verticalSpacing="6dp"
android:horizontalSpacing="6dp"
android:stretchMode="columnWidth"
android:gravity="center"
></GridView>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<include layout="#layout/progress_screen" />
</merge>
Adapter class
public class PropertyListAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<Property> data = null;
private int layoutID;
private LayoutInflater layout_inflater;
ImageManagerGallery imageManager;
DebugHelper debug = new DebugHelper(true);
public PropertyListAdapter(Context c, int layoutID, ArrayList<Property> list){
mContext = c;
data = list;
this.layoutID = layoutID;
imageManager = new ImageManagerGallery(c);
}
public void add(ArrayList<Property> list){
if(this.data != null){
this.data.clear();
this.data.addAll(list);
notifyDataSetChanged();
}
}
#Override
public int getCount() {
if(this.data != null){
return this.data.size();
}
return 0;
}
#Override
public Property getItem(int position) {
if(this.data != null){
return this.data.get(position);
}
return null;
}
#Override
public long getItemId(int position) {
if(this.data != null){
return Common.getStringAsInteger(this.data.get(position).getSiteid());
}
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
VHHomeProperty viewHolder;
Bitmap bitmap;
if(convertView == null){
this.layout_inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = this.layout_inflater.inflate(layoutID, null);
viewHolder = new VHHomeProperty();
viewHolder.iv_imageView = (ImageView)convertView.findViewById(R.id.iv_property_image);
viewHolder.tv_text = (TextView)convertView.findViewById(R.id.tv_home_property_text);
viewHolder.tv_title = (TextView)convertView.findViewById(R.id.tv_property_title);
viewHolder.progress = (ProgressBar)convertView.findViewById(R.id.idProgressBar);
convertView.setTag(viewHolder);
}else{
viewHolder = (VHHomeProperty) convertView.getTag();
}
if(this.data != null){
Property locProp = this.data.get(position);
viewHolder.tv_title.setText(locProp.getTitle());
debug.print(locProp.getHomePageText());
String htmlString = Html.fromHtml(Html.fromHtml(locProp.getHomePageText()).toString()).toString();
debug.print(htmlString);
viewHolder.tv_text.setText(htmlString);
try{
viewHolder.iv_imageView.setTag(locProp.getImagePath());
imageManager.displayImage(locProp.getImagePath(), viewHolder.iv_imageView, viewHolder.progress);
}catch(Exception e){
}
}
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)convertView.getLayoutParams();
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
return convertView;
}
}
grid_home_property.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:background="#drawable/home_property_selector"
android:gravity="top"
android:padding="3dp" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/iv_property_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:src="#drawable/sample_property_image" />
<ProgressBar
android:id="#+id/idProgressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<TextView
android:id="#+id/tv_home_property_text"
style="#style/homePropertyText"
android:layout_below="#+id/tv_property_title" />
<TextView
android:id="#+id/tv_property_title"
style="#style/homePropertyTitle"
android:layout_alignLeft="#+id/relativeLayout1"
android:layout_below="#+id/relativeLayout1"
android:layout_marginTop="14dp"
android:text="Huntingdon" />
</RelativeLayout>

Categories

Resources