这是我的适配器类代码:
public class ChatAdapter extends ArrayAdapter<Chat> {
private final Context context;
private final ArrayList<Chat> values;
ImageLoader imageloader;
Datamodel dm;
public ChatAdapter(Context context, ArrayList<Chat> values) {
super(context, R.layout.list_row_layout_odd, values);
// TODO Auto-generated constructor stub
this.context = context;
this.values = values;
imageloader = new ImageLoader(context);
}
public void addMessage(Chat chat) {
values.add(chat);
this.notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.list_row_layout_odd,
parent, false);
RoundedImageView userImg = (RoundedImageView) convertView.findViewById(R.id.user_img);
RelativeLayout root = (RelativeLayout) convertView
.findViewById(R.id.even_container);
TextView tv = (TextView) convertView.findViewById(R.id.text);
RoundedImageView oddImg = (RoundedImageView) convertView
.findViewById(R.id.odd_bubble);
ImageView leftimageicon=(ImageView)root.findViewById(R.id.left);
ImageView rightimageicon=(ImageView)root.findViewById(R.id.right);
Typeface fontArial = Typeface.createFromAsset(context.getAssets(),
"fonts/ARIAL.TTF");
SharedPreferences prefs = context.getSharedPreferences(
AppConstants.LOGIN_PREFS, Context.MODE_PRIVATE);
String K = prefs.getString("Member_id", "");
Chat chat = values.get(position);
String t = chat.getRecieverID();
tv.setText(chat.getMessage());
tv.setTypeface(fontArial);
AQuery aq = new AQuery(context);
if (chat.getSenderID().equals(prefs.getString("Member_id", ""))) {
root.setBackgroundColor(Color.parseColor("#07000000"));
tv.setTextColor(Color.parseColor("#636363"));
tv.setBackgroundColor(Color.parseColor("#00ad9a"));
leftimageicon.setVisibility(View.GONE);
rightimageicon.setVisibility(View.VISIBLE);
oddImg.setVisibility(View.GONE);
} else {
root.setBackgroundColor(Color.parseColor("#07000000"));
tv.setTextColor(Color.parseColor("#bdbdbd"));
tv.setBackgroundColor(Color.parseColor("#ffffff"));
oddImg.setVisibility(View.VISIBLE);
aq.id(oddImg).image(
"http://api.lociiapp.com/TransientStorage/" + K + ".jpg");
leftimageicon.setVisibility(View.VISIBLE);
rightimageicon.setVisibility(View.GONE);
oddImg.setVisibility(View.VISIBLE);
}
return convertView;
}
}
list_row_layout_odd.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/even_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<com.lociiapp.utils.RoundedImageView
android:id="@+id/odd_bubble"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:layout_margin="5dip"
android:visibility="visible" />
<LinearLayout
android:id="@+id/shareRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_toRightOf="@+id/odd_bubble"
android:background="#07000000"
android:orientation="horizontal"
android:weightSum="1" >
<ImageView
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="15dip"
android:layout_weight=".10"
android:src="@drawable/callout_left" />
<TextView
android:id="@+id/text"
android:layout_width="155dip"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="15dip"
android:layout_toLeftOf="@+id/left"
android:textColor="#636363"
android:textSize="20sp" />
<ImageView
android:id="@+id/right"
android:layout_width="wrap_content"![enter image description here][1]
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:layout_marginTop="15dip"
android:layout_toLeftOf="@+id/text"
android:layout_weight=".10"
android:src="@drawable/callout_right" />
</LinearLayout>
</RelativeLayout>
我能够显示chatlistview但是有问题我无法根据屏幕设置项目我试图设置左右文本视图但右文本视图不会设计。我必须制作适配器,以便我可以根据给定的屏幕对发送和接收器textview和图像视图进行拼写。以下是欲望屏幕: 下面是我当前的屏幕:分别是
我不知道在哪里做错了请告诉我并建议我。
答案 0 :(得分:1)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/even_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.10" >
<com.lociiapp.utils.RoundedImageView
android:id="@+id/odd_bubble"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_margin="5dip"
android:visibility="visible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.90" >
<LinearLayout
android:id="@+id/shareRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:background="#07000000"
android:orientation="horizontal" >
<ImageView
android:id="@+id/left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".10"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="15dip"
android:layout_weight="0.5"
android:textColor="#636363"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>