채팅 앱을 사용할 예정이지만 수신 메시지의 9 가지 패치 이미지를 왼쪽 및 오른쪽으로 찾을 수 없습니다. 나가는 메시지를 오른쪽으로.
java.lang.ClassCastException가 : android.widget.RelativeLayout $의 LayoutParams이 android.widget.LinearLayout $의 LayoutParams 캐스트 할 수없는
내 어댑터 클래스 :
LayoutParams
를 사용하는 동안 나는이 예외를 가지고
public class MessageAdapter extends ResourceCursorAdapter {
private final int backgroundDrawableIn, backgroundDrawableOut
private final MessageListActivity mActivity;
private String displayName = null;
private final int textSize, textColor;
private final boolean convertNCR;
private final boolean showEmoticons;
private static class ViewHolder {
TextView tvBody;
TextView tvDate;
ImageView ivPhoto;
View vRead;
public View vPending;
// public View vLayout;
public RelativeLayout vLayout;
}
public MessageAdapter(final MessageListActivity c, final Uri u) {
super(c, R.layout.messagelist_item, getCursor(c.getContentResolver(), u), true);
mActivity = c;
backgroundDrawableIn = PreferencesActivity.getBubblesIn(c);
backgroundDrawableOut = PreferencesActivity.getBubblesOut(c);
textSize = PreferencesActivity.getTextsize(c);
textColor = PreferencesActivity.getTextcolor(c);
convertNCR = PreferencesActivity.decodeDecimalNCR(c);
showEmoticons = PreferencesActivity.showEmoticons(c);
int threadId = -1;
if (u == null || u.getLastPathSegment() == null) {
threadId = -1;
} else {
threadId = Integer.parseInt(u.getLastPathSegment());
}
final Conversation conv = Conversation.getConversation(c, threadId, false);
// Address
String address = null;
//Name
String name = null;
if (conv == null) {
address = null;
name = null;
displayName = null;
} else {
final Contact contact = conv.getContact();
address = contact.getNumber();
name = contact.getName();
displayName = contact.getDisplayName();
}
}
@Override
public final void bindView(final View view, final Context context, final Cursor cursor) {
final Message m = Message.getMessage(context, cursor);
ViewHolder holder = (ViewHolder) view.getTag();
if (holder == null) {
holder = new ViewHolder();
holder.tvBody = (TextView) view.findViewById(R.id.body);
holder.tvDate = (TextView) view.findViewById(R.id.date);
holder.ivPhoto = (ImageView) view.findViewById(R.id.picture);
holder.vRead = view.findViewById(R.id.read);
holder.vPending = view.findViewById(R.id.pending);
//holder.vLayout = view.findViewById(R.id.layout);
holder.vLayout=(RelativeLayout)view.findViewById(R.id.layout);
view.setTag(holder);
}
if (textSize > 0) {
holder.tvBody.setTextSize(textSize);
}
final int col = textColor;
if (col != 0) {
holder.tvBody.setTextColor(col);
holder.tvDate.setTextColor(col);
}
int t = m.getType();
String subject = m.getSubject();
if (subject == null) {
subject = "";
} else {
subject = ": " + subject;
}
// incoming/outgoing/pending
int pendingvisability = View.GONE;
switch (t) {
case Message.SMS_DRAFT:
pendingvisability = View.VISIBLE;
case Message.SMS_OUT:
case Message.MMS_OUT:
try {
holder.vLayout.setBackgroundResource(backgroundDrawableOut);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) holder.vLayout.getLayoutParams();
layoutParams.gravity = Gravity.LEFT;
holder.vLayout.setLayoutParams(layoutParams);
LinearLayout.LayoutParams lp=(LinearLayout.LayoutParams) holder.tvBody.getLayoutParams();
layoutParams.gravity = Gravity.LEFT;
holder.tvBody.setLayoutParams(lp);
LinearLayout.LayoutParams lpp=(LinearLayout.LayoutParams) holder.tvDate.getLayoutParams();
layoutParams.gravity = Gravity.LEFT;
holder.tvDate.setLayoutParams(lpp);
} catch (OutOfMemoryError e) {
Log.e(TAG, "OOM while setting bg", e);
}
break;
case Message.SMS_IN:
case Message.MMS_IN:
default:
try {
holder.vLayout.setBackgroundResource(backgroundDrawableIn);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) holder.vLayout.getLayoutParams();
layoutParams.gravity = Gravity.RIGHT;
holder.vLayout.setLayoutParams(layoutParams);
LinearLayout.LayoutParams lp=(LinearLayout.LayoutParams) holder.tvBody.getLayoutParams();
layoutParams.gravity = Gravity.RIGHT;
holder.tvBody.setLayoutParams(lp);
LinearLayout.LayoutParams lpp=(LinearLayout.LayoutParams) holder.tvDate.getLayoutParams();
layoutParams.gravity = Gravity.RIGHT;
holder.tvDate.setLayoutParams(lpp);
} catch (OutOfMemoryError e) {
Log.e(TAG, "OOM while setting bg", e);
}
holder.vPending.setVisibility(View.GONE);
break;
}
holder.vPending.setVisibility(pendingvisability);
if (m.getRead() == 0) {
holder.vRead.setVisibility(View.VISIBLE);
} else {
holder.vRead.setVisibility(View.INVISIBLE);
}
final long time = m.getDate();
holder.tvDate.setText(Conversation_list.getDate(context, time));
final Bitmap pic = m.getPicture();
if (pic != null) {
if (pic == Message.BITMAP_PLAY) {
holder.ivPhoto.setImageResource(R.drawable.mms_play_btn);
} else {
holder.ivPhoto.setImageBitmap(pic);
}
holder.ivPhoto.setVisibility(View.VISIBLE);
final Intent i = m.getContentIntent();
holder.ivPhoto.setOnClickListener(VSMS.getOnClickStartActivity(context, i));
} else {
holder.ivPhoto.setVisibility(View.GONE);
holder.ivPhoto.setOnClickListener(null);
}
CharSequence text = m.getBody();
if (text == null) {
holder.tvBody.setVisibility(View.INVISIBLE);
} else {
if (convertNCR) {
text = Converter.convertDecNCR2Char(text);
}
if (showEmoticons) {
text = SmileyParser.getInstance(context).addSmileySpans(text);
}
holder.tvBody.setText(text);
holder.tvBody.setVisibility(View.VISIBLE);
}
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<View
android:id="@+id/read"
android:background="#007e88"
android:layout_height="wrap_content"
android:layout_width="5dip"
android:layout_marginRight="1dip"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:id="@+id/layout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/body"
android:text="@+id/body"
android:layout_gravity="right"
android:layout_below="@+id/addr"
android:singleLine="false"
android:autoLink="all"
/>
<ImageView
android:id="@+id/pending"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_marginLeft="2dip"
android:layout_toRightOf="@+id/date"
android:src="@drawable/ic_sms_mms_pending"
android:visibility="gone"
/>
<TextView
android:layout_width="wrap_content"
android:layout_below="@id/body"
android:layout_gravity="right"
android:layout_height="wrap_content"
android:id="@+id/date"
android:text="@+id/date"
android:singleLine="true"/>
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/picture"
android:visibility="gone"
android:maxWidth="178dip"
android:maxHeight="178dip"
android:adjustViewBounds="true"
android:background="@android:drawable/picture_frame"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
스택 추적을 게시 할 수 있습니까? – efekctive
상대 레이아웃이 있고 선형 레이아웃으로 변환하려고합니다. – X3Btel
나는 상대적인 레이아웃을 사용했지만 나에게 도움이되지 않는다. – fa1234