[英]listview issue from android version 4.4(kitkat) and above android version
I am developing chat application.i am facing issue in listview odd behavior. 我正在开发聊天应用程序。我在listview奇怪行为中面临问题。 My code is working perfectly below android OS 4.4 .
我的代码在android OS 4.4下运行良好 。 but when running my application in 4.4 kitkat then i am facing issue.
但是当在4.4 kitkat中运行我的应用程序时,我面临问题。
please check below Screenshots. 请检查以下屏幕截图。
Suppose my First message length is large then my Second message height get same. 假设我的第一条消息长度很大,然后我的第二条消息高度相同。
In Second Screenshot it will show proper view of last message. 在第二个屏幕截图中,它将显示最后一条消息的正确视图。 Because i have close my keyboard and adapter get refresh at the same time first visible view height gets increase automatically.
因为我已经关闭,所以键盘和适配器会在同一时间刷新,因此第一个可见的视图高度会自动增加。
public class ChatAdapter extends BaseAdapter {
LayoutInflater mInflater;
ChatActivity chatActivity;
private DatabaseHandler DatabaseHandler;
private DatabaseHandler dbHelper;
private List<HBMessage> mList = new ArrayList<HBMessage>();
private Context mContext;
public ChatAdapter(ChatActivity chatActivity) {
this.chatActivity = chatActivity;
mContext = chatActivity;
DatabaseHandler = new DatabaseHandler(mContext);
dbHelper = new DatabaseHandler(mContext);
}
@Override
public int getCount() {
return mList.size();
}
@Override
public HBMessage getItem(int position) {
return mList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class Holder {
private RelativeLayout mSimpleRecieveLayout, mSimpleSenderLayout, rlImageSendLayout, rlImageReceiveLayout, mRecieveImageLayout;
private LinearLayout mSentImageLayout;
private TextView simpleFriendMessage, simpleFriendMessageTime, simpleMyMessage, simpleMyMessageTime, mtxtImageSentTime,
mtxtImageRecieveTime;
private ImageView mimgSent, mimgRecieve, mplayordownload, mplayorupload;
private TextView mMsgStatus, mtxtImageStatus;
private ProgressBar mSentProgress, mDownloadProgress;
}
@SuppressLint("InflateParams")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Holder mHolder;
if (convertView == null) {
mHolder = new Holder();
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.single_chat_item, null);
mHolder.mSimpleRecieveLayout = (RelativeLayout) convertView.findViewById(R.id.recive_layout);
mHolder.mSimpleSenderLayout = (RelativeLayout) convertView.findViewById(R.id.sender_layout);
mHolder.mSentImageLayout = (LinearLayout) convertView.findViewById(R.id.sentImageLayout);
mHolder.mRecieveImageLayout = (RelativeLayout) convertView.findViewById(R.id.recieveImageLayout);
mHolder.simpleFriendMessage = (TextView) convertView.findViewById(R.id.txtMesssageSender);
mHolder.simpleFriendMessageTime = (TextView) convertView.findViewById(R.id.txtTimeSender);
mHolder.mtxtImageRecieveTime = (TextView) convertView.findViewById(R.id.txtImageRecieveTime);
mHolder.simpleMyMessage = (TextView) convertView.findViewById(R.id.txtMesssageRecieve);
mHolder.simpleMyMessageTime = (TextView) convertView.findViewById(R.id.txtTimeRecieve);
mHolder.mtxtImageSentTime = (TextView) convertView.findViewById(R.id.txtImageSentTime);
mHolder.mMsgStatus = (TextView) convertView.findViewById(R.id.txtStatusSender);
mHolder.mtxtImageStatus = (TextView) convertView.findViewById(R.id.txtImageSentStatus);
mHolder.mimgSent = (ImageView) convertView.findViewById(R.id.imgSent);
mHolder.mimgRecieve = (ImageView) convertView.findViewById(R.id.imgRecieve);
mHolder.mSentProgress = (ProgressBar) convertView.findViewById(R.id.sentProgress);
mHolder.mplayordownload = (ImageView) convertView.findViewById(R.id.playordownload);
mHolder.mplayorupload = (ImageView) convertView.findViewById(R.id.playorupload);
mHolder.mDownloadProgress = (ProgressBar) convertView.findViewById(R.id.downloadProgress);
mHolder.rlImageSendLayout = (RelativeLayout) convertView.findViewById(R.id.chat_rlSendImage);
mHolder.rlImageReceiveLayout = (RelativeLayout) convertView.findViewById(R.id.chat_rlReceiveImage);
int tempWidth = (int) (BaseApplication.SCREEN_WIDTH * 0.28);
int tempHeight = (int) (BaseApplication.SCREEN_WIDTH * 0.26);
int imageSize = (int) (tempHeight * 0.84);
LinearLayout.LayoutParams param1 = (LayoutParams) mHolder.rlImageSendLayout.getLayoutParams();
param1.width = tempWidth;
param1.height = tempHeight;
mHolder.rlImageSendLayout.setLayoutParams(param1);
RelativeLayout.LayoutParams param2 = (android.widget.RelativeLayout.LayoutParams) mHolder.rlImageReceiveLayout
.getLayoutParams();
param2.width = tempWidth;
param2.height = tempHeight;
mHolder.rlImageReceiveLayout.setLayoutParams(param2);
RelativeLayout.LayoutParams param3 = (android.widget.RelativeLayout.LayoutParams) mHolder.mimgSent.getLayoutParams();
param3.width = imageSize;
param3.height = imageSize;
mHolder.mimgSent.setLayoutParams(param3);
RelativeLayout.LayoutParams param4 = (android.widget.RelativeLayout.LayoutParams) mHolder.mimgRecieve.getLayoutParams();
param4.width = imageSize;
param4.height = imageSize;
mHolder.mimgRecieve.setLayoutParams(param4);
convertView.setTag(mHolder);
} else {
mHolder = (Holder) convertView.getTag();
}
if ((mList.get(position).getFromJID().equalsIgnoreCase(UserDetails.getInstance(mContext).getJabberId() + WSUtils.CHAT_DOMAIN))) {
setMyLayout(mList.get(position), mHolder, position, convertView);
} else {
setOtherLayout(mList.get(position), mHolder, position);
}
return convertView;
}
XML inflater Layout XML充气机布局
<RelativeLayout
android:id="@+id/sender_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:clickable="false"
android:visibility="visible" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:background="@drawable/chat_sender"
android:orientation="vertical" >
<com.hb.utils.CustomTextView
android:id="@+id/txtMesssageSender"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="@dimen/chatpadding"
android:layout_marginRight="@dimen/chatpadding"
android:layout_weight="1"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/color_text"
android:textSize="@dimen/chattext"
app:type="common" />
<com.hb.utils.CustomTextView
android:id="@+id/txtTimeSender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginBottom="@dimen/chat_nagetive_pad"
android:layout_marginRight="@dimen/chatpadding"
android:layout_marginEnd="@dimen/chatpadding"
android:layout_marginTop="2dp"
android:textColor="@color/graychars"
android:textSize="@dimen/chattime"
app:type="common" />
<com.hb.utils.CustomTextView
android:id="@+id/txtStatusSender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginRight="@dimen/chatpadding"
android:layout_marginEnd="@dimen/chatpadding"
android:requiresFadingEdge="vertical"
android:textColor="@color/color_regular_green"
android:textSize="@dimen/chattime"
app:type="common" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/recive_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/chat_receiver"
android:orientation="vertical" >
<com.hb.utils.CustomTextView
android:id="@+id/txtMesssageRecieve"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="@dimen/chatpadding"
android:layout_marginRight="@dimen/chatpadding"
android:layout_weight="1"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/color_text"
android:textSize="@dimen/chattext"
app:type="common" />
<com.hb.utils.CustomTextView
android:id="@+id/txtTimeRecieve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginRight="@dimen/chatpadding"
android:layout_marginEnd="@dimen/chatpadding"
android:layout_marginTop="2dp"
android:requiresFadingEdge="vertical"
android:textColor="@color/graychars"
android:textSize="@dimen/chattime"
app:type="common" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/sentImageLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/chat_rlSendImage"
android:layout_width="210px"
android:layout_height="210px"
android:layout_gravity="end"
android:background="@drawable/chat_sender"
android:gravity="end|center_vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/chatpadding" >
<ImageView
android:id="@+id/imgSent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop"
android:src="@drawable/noimage" />
<ProgressBar
android:id="@+id/sentProgress"
style="?android:attr/progressBarStyleInverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="visible" />
<ImageView
android:id="@+id/playorupload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/upload"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
<com.hb.utils.CustomTextView
android:id="@+id/txtImageSentTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginBottom="@dimen/chat_nagetive_pad"
android:layout_marginRight="@dimen/chatimagetext"
android:layout_marginEnd="@dimen/chatimagetext"
android:layout_marginTop="2dp"
android:textColor="@color/graychars"
android:textSize="@dimen/chattime"
app:type="common" />
<com.hb.utils.CustomTextView
android:id="@+id/txtImageSentStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginRight="@dimen/chatimagetext"
android:layout_marginEnd="@dimen/chatimagetext"
android:textColor="@color/color_regular_green"
android:textSize="@dimen/chattime"
app:type="common" />
</LinearLayout>
<RelativeLayout
android:id="@+id/recieveImageLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/chat_rlReceiveImage"
android:layout_width="210px"
android:layout_height="210px"
android:background="@drawable/chat_receiver"
android:gravity="center_vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/chatpadding" >
<ImageView
android:id="@+id/imgRecieve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop"
android:src="@drawable/noimage" />
<ProgressBar
android:id="@+id/downloadProgress"
style="?android:attr/progressBarStyleInverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />
<ImageView
android:id="@+id/playordownload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/download" />
</RelativeLayout>
</RelativeLayout>
<com.hb.utils.CustomTextView
android:id="@+id/txtImageRecieveTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/chat_rlReceiveImage"
android:layout_alignEnd="@id/chat_rlReceiveImage"
android:layout_below="@id/chat_rlReceiveImage"
android:textColor="@color/graychars"
android:textSize="@dimen/chattime"
app:type="common" />
</RelativeLayout>
private synchronized void setOtherLayout(HBMessage hbMessage, final Holder mHolder, final int position) {
if (hbMessage.getMsgType().equalsIgnoreCase(HBMessage.IMAGE)) {
mHolder.mSimpleRecieveLayout.setVisibility(View.GONE);
mHolder.mSimpleSenderLayout.setVisibility(View.GONE);
mHolder.mSentImageLayout.setVisibility(View.GONE);
mHolder.mRecieveImageLayout.setVisibility(View.VISIBLE);
mHolder.mplayordownload.setTag(position);
mHolder.mimgRecieve.setTag(position);
String str = hbMessage.getMessage();
final String seperatedString[] = str.split("##@!@##");
if (hbMessage.getMediaStatus().equals(HBMessage.NOTDOWNLOADED)) {
mHolder.mplayordownload.setVisibility(View.VISIBLE);
mHolder.mDownloadProgress.setVisibility(View.GONE);
} else if (hbMessage.getMediaStatus().equals(HBMessage.DOWNLOADING)) {
mHolder.mplayordownload.setVisibility(View.GONE);
mHolder.mDownloadProgress.setVisibility(View.VISIBLE);
} else {
mHolder.mplayordownload.setVisibility(View.GONE);
mHolder.mDownloadProgress.setVisibility(View.GONE);
}
mHolder.mtxtImageRecieveTime.setText(StaticUtils.getChatHistoryDateTime(hbMessage.getMessageTime()));
chatActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
mHolder.mimgRecieve.setImageBitmap(getImageFromBase64StringWithTimeStamp(seperatedString[0]));
}
});
mHolder.mplayordownload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View paramView) {
paramView.setVisibility(View.GONE);
int pos = (Integer) paramView.getTag();
HBMessage message = getItem(pos);
final String name[] = message.getMessage().split("##@!@##");
if (dbHelper.isImageAvaialble(name[1])) {
DatabaseHandler.updateImageStatus(mContext, message.getMessageId(), HBMessage.DOWNLOADED, HBMessage.CHAT_SINGLE);
message.setMediaStatus(HBMessage.DOWNLOADED);
setItem(message, pos);
} else {
((ViewGroup) paramView.getParent()).findViewById(R.id.downloadProgress).setVisibility(View.VISIBLE);
message.setMediaStatus(HBMessage.DOWNLOADING);
setItem(message, position);
chatActivity.callDownloadfileProcess(pos, ((ViewGroup) paramView.getParent()));
}
}
});
} else {
mHolder.mSimpleRecieveLayout.setVisibility(View.VISIBLE);
mHolder.mSimpleSenderLayout.setVisibility(View.GONE);
mHolder.mSentImageLayout.setVisibility(View.GONE);
mHolder.mRecieveImageLayout.setVisibility(View.GONE);
mHolder.simpleMyMessageTime.setText(StaticUtils.getChatHistoryDateTime(hbMessage.getMessageTime()));
mHolder.simpleMyMessage.setText(hbMessage.getMessage());
}
}
private synchronized void setMyLayout(HBMessage hbMessage, final Holder mHolder, int position, View view) {
if (hbMessage.getMsgType().equalsIgnoreCase(HBMessage.IMAGE)) {
mHolder.mSimpleRecieveLayout.setVisibility(View.GONE);
mHolder.mSimpleSenderLayout.setVisibility(View.GONE);
mHolder.mRecieveImageLayout.setVisibility(View.GONE);
mHolder.mSentImageLayout.setVisibility(View.VISIBLE);
String str = hbMessage.getMessage();
final String seperatedString[] = str.split("##@!@##");
mHolder.mimgSent.setTag(position);
mHolder.mplayorupload.setTag(position);
if (hbMessage.getMediaStatus().equals(HBMessage.NOTUPLOADED)) {
mHolder.mplayorupload.setVisibility(View.VISIBLE);
mHolder.mSentProgress.setVisibility(View.GONE);
} else if (hbMessage.getMediaStatus().equals(HBMessage.UPLOADING)) {
mHolder.mplayorupload.setVisibility(View.GONE);
mHolder.mSentProgress.setVisibility(View.VISIBLE);
} else {
mHolder.mplayorupload.setVisibility(View.GONE);
mHolder.mSentProgress.setVisibility(View.GONE);
}
mHolder.mSentProgress.setTag(view);
mHolder.mtxtImageSentTime.setText(StaticUtils.getChatHistoryDateTime(hbMessage.getMessageTime()));
chatActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
mHolder.mimgSent.setImageBitmap(getImageFromBase64StringWithTimeStamp(seperatedString[0]));
}
});
mHolder.mtxtImageStatus.setText(hbMessage.getMessageStatus());
if (hbMessage.getMessageStatus().equals(HBMessage.STATUS_PENDDING)
|| hbMessage.getMessageStatus().equals(HBMessage.STATUS_FAILED)) {
mHolder.mtxtImageStatus.setTextColor(mContext.getResources().getColor(R.color.color_pending_red));
} else if (hbMessage.getMessageStatus().equals(HBMessage.STATUS_DELIVERED)) {
mHolder.mtxtImageStatus.setTextColor(mContext.getResources().getColor(R.color.color_black));
} else
mHolder.mtxtImageStatus.setTextColor(mContext.getResources().getColor(R.color.color_green));
if (hbMessage.isAutoUpload()) {
ImageHolder mImageHolder = dbHelper.getImageHolder(seperatedString[1]);
File mFile = StaticUtils.bitmapToFile(mImageHolder.getBitmap(), mImageHolder.getFileName(), false);
if (mFile != null) {
hbMessage.setAutoUpload(false);
mList.set(position, hbMessage);
chatActivity.uploadToserver(mFile, mImageHolder.getFileName(), hbMessage, position, view);
} else {
CommonUtils.showSingleBtnDialog("Image Not Available", mContext, null);
}
}
mHolder.mplayorupload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View paramView) {
int pos = (Integer) paramView.getTag();
HBMessage message = getItem(pos);
final String seperatedString[] = message.getMessage().split("##@!@##");
ImageHolder mImageHolder = dbHelper.getImageHolder(seperatedString[1]);
File mFile = StaticUtils.bitmapToFile(mImageHolder.getBitmap(), mImageHolder.getFileName(), false);
if (mFile != null) {
paramView.setVisibility(View.GONE);
ProgressBar pb = (ProgressBar) ((ViewGroup) paramView.getParent()).findViewById(R.id.sentProgress);
pb.setVisibility(View.VISIBLE);
View view = (View) pb.getTag();
((TextView) view.findViewById(R.id.txtImageSentStatus)).setText(HBMessage.STATUS_PENDDING);
message.setMediaStatus(HBMessage.UPLOADING);
message.setMessageStatus(HBMessage.STATUS_PENDDING);
setItem(message, pos);
chatActivity.uploadToserver(mFile, mFile.getName(), message, pos, view);
DatabaseHandler.updateImageStatus(mContext, message.getMessageId(), HBMessage.UPLOADING, HBMessage.CHAT_SINGLE);
} else {
CommonUtils.showSingleBtnDialog("Image Not Available", mContext, null);
}
}
});
} else {
mHolder.mSimpleRecieveLayout.setVisibility(View.GONE);
mHolder.mSimpleSenderLayout.setVisibility(View.VISIBLE);
mHolder.mSentImageLayout.setVisibility(View.GONE);
mHolder.mRecieveImageLayout.setVisibility(View.GONE);
mHolder.simpleFriendMessageTime.setText(StaticUtils.getChatHistoryDateTime(hbMessage.getMessageTime()));
mHolder.simpleFriendMessage.setText(hbMessage.getMessage());
mHolder.mMsgStatus.setText(hbMessage.getMessageStatus());
if (hbMessage.getMessageStatus().equals(HBMessage.STATUS_PENDDING)
|| hbMessage.getMessageStatus().equals(HBMessage.STATUS_FAILED)) {
mHolder.mMsgStatus.setTextColor(mContext.getResources().getColor(R.color.color_pending_red));
} else if (hbMessage.getMessageStatus().equals(HBMessage.STATUS_DELIVERED)) {
mHolder.mMsgStatus.setTextColor(mContext.getResources().getColor(R.color.color_black));
} else
mHolder.mMsgStatus.setTextColor(mContext.getResources().getColor(R.color.color_green));
}
}
Because of the behaviour of view recycling, everything that has to do with content has to be set and un-set regardless if convertView
is null
or not. 由于视图回收的行为,与
convertView
无关的所有内容都必须设置和取消设置,无论convertView
是否为null
。 You should start by moving the code that has nothing to do with viewHolder binding to after the if-else. 您应该首先在if-else 之后移动与viewHolder绑定无关的代码。
Another option would be to start using RecyclerView
which is esentially like ListView
that has the recycling mechanism improved (and a lot more). 另一个选择是开始使用
RecyclerView
,它本质上类似于ListView
,它的回收机制得到了改进(还有很多)。 Here is a guide for that. 这是一个指南 。
There are pieces of code you need to execute for all the views, regardless of them being new or recycled. 无论是新视图还是回收的视图,都需要为所有视图执行一些代码。 Only the viewholder init part is to be executed only for new views.
仅对于新视图,将只执行viewholder init部分。
if (convertView == null) {
mHolder = new Holder();
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.single_chat_item, null);
mHolder.mSimpleRecieveLayout = (RelativeLayout) convertView.findViewById(R.id.recive_layout);
mHolder.mSimpleSenderLayout = (RelativeLayout) convertView.findViewById(R.id.sender_layout);
mHolder.mSentImageLayout = (LinearLayout) convertView.findViewById(R.id.sentImageLayout);
mHolder.mRecieveImageLayout = (RelativeLayout) convertView.findViewById(R.id.recieveImageLayout);
mHolder.simpleFriendMessage = (TextView) convertView.findViewById(R.id.txtMesssageSender);
mHolder.simpleFriendMessageTime = (TextView) convertView.findViewById(R.id.txtTimeSender);
mHolder.mtxtImageRecieveTime = (TextView) convertView.findViewById(R.id.txtImageRecieveTime);
mHolder.simpleMyMessage = (TextView) convertView.findViewById(R.id.txtMesssageRecieve);
mHolder.simpleMyMessageTime = (TextView) convertView.findViewById(R.id.txtTimeRecieve);
mHolder.mtxtImageSentTime = (TextView) convertView.findViewById(R.id.txtImageSentTime);
mHolder.mMsgStatus = (TextView) convertView.findViewById(R.id.txtStatusSender);
mHolder.mtxtImageStatus = (TextView) convertView.findViewById(R.id.txtImageSentStatus);
mHolder.mimgSent = (ImageView) convertView.findViewById(R.id.imgSent);
mHolder.mimgRecieve = (ImageView) convertView.findViewById(R.id.imgRecieve);
mHolder.mSentProgress = (ProgressBar) convertView.findViewById(R.id.sentProgress);
mHolder.mplayordownload = (ImageView) convertView.findViewById(R.id.playordownload);
mHolder.mplayorupload = (ImageView) convertView.findViewById(R.id.playorupload);
mHolder.mDownloadProgress = (ProgressBar) convertView.findViewById(R.id.downloadProgress);
mHolder.rlImageSendLayout = (RelativeLayout) convertView.findViewById(R.id.chat_rlSendImage);
mHolder.rlImageReceiveLayout = (RelativeLayout) convertView.findViewById(R.id.chat_rlReceiveImage);
convertView.setTag(mHolder);
} else {
mHolder = (Holder) convertView.getTag();
}
// This is now executed for all your views.
int tempWidth = (int) (BaseApplication.SCREEN_WIDTH * 0.28);
int tempHeight = (int) (BaseApplication.SCREEN_WIDTH * 0.26);
int imageSize = (int) (tempHeight * 0.84);
LinearLayout.LayoutParams param1 = (LayoutParams) mHolder.rlImageSendLayout.getLayoutParams();
param1.width = tempWidth;
param1.height = tempHeight;
mHolder.rlImageSendLayout.setLayoutParams(param1);
RelativeLayout.LayoutParams param2 = (android.widget.RelativeLayout.LayoutParams) mHolder.rlImageReceiveLayout
.getLayoutParams();
param2.width = tempWidth;
param2.height = tempHeight;
mHolder.rlImageReceiveLayout.setLayoutParams(param2);
RelativeLayout.LayoutParams param3 = (android.widget.RelativeLayout.LayoutParams) mHolder.mimgSent.getLayoutParams();
param3.width = imageSize;
param3.height = imageSize;
mHolder.mimgSent.setLayoutParams(param3);
RelativeLayout.LayoutParams param4 = (android.widget.RelativeLayout.LayoutParams) mHolder.mimgRecieve.getLayoutParams();
param4.width = imageSize;
param4.height = imageSize;
mHolder.mimgRecieve.setLayoutParams(param4);
Also, you should really consider reading more about having different view types in an adaptor (myLayout and otherLayout in your case). 此外,您应该真正考虑阅读有关在适配器中使用不同视图类型的更多信息(在您的情况下为myLayout和otherLayout)。 A starting point would be this .
一个起点就是这个 。
Finally I have solved this issue by applying stupid thing.Why i am facing issue,that i really don't know and Why its get solved after applying patch that i really don't know.
**My Solution:**
setMyLayout()
{
mHolder.mSentMessageLayout
.setBackgroundResource(R.drawable.chat_sender);
}
setOtherLayout()
{
mHolder.mRecieveMessageLayout
.setBackgroundResource(R.drawable.chat_receiver);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.