android - How to fix Adapter when listview is scroll -
i want position testview left , right if user sender, position left else postion right work fine when scroll or down position every thing right here code
string myisme="1"; private int self = 100; public chatdisplayadapter(context c, arraylist<string> id, arraylist<string> fname, arraylist<string> lname, arraylist<string> time, arraylist<string> senderid, arraylist<string> sendtoid, arraylist<string> sticker,arraylist<string> pic) { this.mcontext = c; this.id = id; this.firstname = fname; this.lastname = lname; this.chattime = time; this.chatsenderid = senderid; this.chatsendtoid = sendtoid; this.chatsticker = sticker; this.chatpic_pic = pic; } public int getcount() { // todo auto-generated method stub return id.size(); } public object getitem(int position) { // todo auto-generated method stub return null; } public long getitemid(int position) { chatsenderid.get(position); if (chatsenderid.get(position).tostring().equals(""+myisme+"")) { return self; } // todo auto-generated method stub return 0; } public view getview(int pos, view child, viewgroup parent) { holder mholder; if (child == null) { // child = layoutinflater.from(mcontext).inflate(r.layout.chat_display_item, parent, false); layoutinflater layoutinflater; layoutinflater = (layoutinflater) mcontext.getsystemservice(context.layout_inflater_service); final boolean isme = chatsenderid.get(pos).equals(myisme); if (isme) { child = layoutinflater.inflate(r.layout.list_item_message_out, null); // if me open , set left // mholder.body.setgravity(gravity.center_vertical | gravity.right); // mholder.txt_chat.setbackgroundresource(r.drawable.chat_item_bg_out); }else { // mholder.body.setgravity(gravity.center_vertical | gravity.left); // mholder.txt_chat.setbackgroundresource(r.drawable.chat_item_bg_in); child = layoutinflater.inflate(r.layout.list_item_message_in, null); } mholder = new holder(); mholder.body =(linearlayout) child.findviewbyid(r.id.lay); mholder.txt_chat = (emojitextview) child.findviewbyid(r.id.label); mholder.txt_time = (textview) child.findviewbyid(r.id.time); mholder.txt_timest = (textview) child.findviewbyid(r.id.time_st); mholder.ts = (textview) child.findviewbyid(r.id.st); mholder.mysticker = (imageview) child.findviewbyid(r.id.mystickerid); mholder.imagechat = (imageview) child.findviewbyid(r.id.image); mholder.chat_pic_body = (relativelayout) child.findviewbyid(r.id.lay_pc); mholder.txt_timepic = (textview) child.findviewbyid(r.id.time_pc); child.settag(mholder); } else { mholder = (holder) child.gettag(); } mholder.txt_timest.settext(chattime.get(pos)); mholder.txt_time.settext(chattime.get(pos)); // mholder.txt_chat.settext(firstname.get(pos)); mholder.txt_chat.setemojitext(firstname.get(pos)); return child; } public class holder { textview txt_id; emojitextview txt_chat; textview txt_time; textview txt_timest,txt_timepic; textview txt_fname; textview txt_lname; textview ts; textview mychatsyncsts; imageview mysticker,imagechat; linearlayout body; relativelayout chat_pic_body; }
}
i want sender test right receiver left
Comments
Post a Comment