Update textview in gallery - android

I am trying to update the textview in my gallery after it has been created using my updateCaption method, however, only the first textview in the gallery gets updated. When I print out my textview, they all have the same ID like android.widget.TextView#40942d60.
public class ImageAdapter extends BaseAdapter {
private static LayoutInflater inflater = null;
private int[] image;
private TextView caption;
public ImageAdapter(Context context) {
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
image = new int[4];
for (int i = 0; i < image.length; i++)
{
image[i] = R.drawable.image;
}
}
public void updateCaption(String text, int position)
{
System.out.println(position + ": text");
caption.setText(text);
System.out.println(caption);
}
public int getCount() {
return image.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView text, dssnum, scnum;
public ImageView image;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View vi = convertView;
ViewHolder holder;
if (convertView == null)
{
vi = inflater.inflate(R.layout.caption, null);
holder = new ViewHolder();
caption = holder.text = (TextView) vi.findViewById(R.id.textView1);
holder.scnum = (TextView) vi.findViewById(R.id.scnum);
holder.dssnum = (TextView) vi.findViewById(R.id.dss_num);
holder.image = (ImageView) vi.findViewById(R.id.image);
vi.setTag(holder);
}
else
holder = (ViewHolder) vi.getTag();
holder.dssnum.setText("Unavailable");
holder.image.setImageResource(image[position]);
holder.text.setText("Not available.");
return vi;
}
}
Does anyone know what I am doing wrong?
Added: how I am using updateCaption
for (int j = 0; j < listOfList.get(i).size(); j++)
{
galleryImageAdapter.updateCaption("test " + j, j);
}

I think this is due to this line...
caption = holder.text = (TextView) vi.findViewById(R.id.textView1);
once all convertView is created, your caption will always point to the textview of the last convertView.

Related

ListView with section headers repeats items when scrolling

I have finally had some luck getting section headers to appear by creating a switch block in my getView(). In doing so I have created a problem with my adapter because now my ListView repeats the top items over and over again. I have found other people with a similar problems, but they were solved by adding convertView.setTag(holder); I already have this, so I believe my problem is something with the way I have set up my switch block. Maybe a syntax problem that is causing things not to line up correctly.
Any help would be appreciated. Here is my adapter:
public class PlayerAdapter extends BaseAdapter {
private Context mContext;
private static final int TYPE_ITEM = 0;
private static final int TYPE_SEPARATOR = 1;
private ArrayList<Player> mPlayers = new ArrayList<>();
private TreeSet<Integer> sectionHeader = new TreeSet<>();
public PlayerAdapter(Context context, ArrayList<Player> players) {
mContext = context;
mPlayers = players;
}
public void addItem(final Player player) {
mPlayers.add(player);
notifyDataSetChanged();
}
public void addSectionHeaderItem(final Player player) {
mPlayers.add(player);
sectionHeader.add(mPlayers.size() -1);
notifyDataSetChanged();
}
#Override
public int getItemViewType(int position) {
return sectionHeader.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
}
#Override
public int getViewTypeCount() {
return 2;
}
#Override
public int getCount() {
return mPlayers.size();
}
#Override
public Object getItem(int position) {
return mPlayers.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public boolean isEnabled(int position) {
int rowType = getItemViewType(position);
if(rowType == TYPE_SEPARATOR) {
return false;
}
return true;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
int rowType = getItemViewType(position);
if (convertView == null) {
Player player = mPlayers.get(position);
switch (rowType){
case TYPE_ITEM:
convertView = LayoutInflater.from(mContext).inflate(R.layout.player_list_item_layout, null);
holder.playerNameTextView = (TextView) convertView.findViewById(R.id.playerNameTextView);
holder.playerValueTextView = (TextView) convertView.findViewById(R.id.playerValueTextView);
holder.remainingCapTextView = (TextView) convertView.findViewById(R.id.remainingCapTextView);
holder.username = (TextView) convertView.findViewById(R.id.opponentUsername);
holder.status = (TextView) convertView.findViewById(R.id.statusTextView);
holder.vsTeamAbbrev = (TextView) convertView.findViewById(R.id.vsTeam);
holder.resultsTextView = (TextView) convertView.findViewById(R.id.resultsTextView);
DecimalFormat formatter = new DecimalFormat("$#,###");
holder.playerNameTextView.setText(player.getName());
holder.playerValueTextView.setText(formatter.format(Double.parseDouble(player.getValue())));
holder.remainingCapTextView.setText(formatter.format(Double.parseDouble(player.getCap())));
holder.username.setText(player.getUsername());
holder.status.setText(player.getStatus());
holder.vsTeamAbbrev.setText(player.getVsTeamAbbrev());
holder.resultsTextView.setText(player.getResultsTextView());
if (player.isMatchMade()) {
holder.status.setVisibility(View.VISIBLE);
}
convertView.setTag(holder);
break;
case TYPE_SEPARATOR:
convertView = LayoutInflater.from(mContext).inflate(R.layout.player_section_header, null);
holder.playerNameTextView = (TextView) convertView.findViewById(R.id.lastPlayer);
holder.lastPlayerDate = (TextView) convertView.findViewById(R.id.lastPlayerDate);
holder.playerNameTextView.setText(player.getName());
holder.lastPlayerDate.setText(player.getLastPlayerDate());
convertView.setTag(holder);
break;
}
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
private static class ViewHolder {
//item views
TextView playerValueTextView;
TextView playerNameTextView;
TextView remainingCapTextView;
TextView username;
TextView status;
TextView vsTeamAbbrev;
TextView resultsTextView;
//section header views
TextView lastPlayer;
TextView lastPlayerDate;
}
}
This turned out to be a pretty simple mistake. I had to move the code that populates my views down below the else clause. This way if convert view is not null, it can still gettag() and populate the data.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
Player player = mPlayers.get(position);
int rowType = getItemViewType(position);
if (convertView == null) {
switch (rowType){
case TYPE_ITEM:
convertView = LayoutInflater.from(mContext).inflate(R.layout.player_list_item_layout, null);
holder.playerNameTextView = (TextView) convertView.findViewById(R.id.playerNameTextView);
holder.playerValueTextView = (TextView) convertView.findViewById(R.id.playerValueTextView);
holder.remainingCapTextView = (TextView) convertView.findViewById(R.id.remainingCapTextView);
holder.username = (TextView) convertView.findViewById(R.id.opponentUsername);
holder.status = (TextView) convertView.findViewById(R.id.statusTextView);
holder.vsTeamAbbrev = (TextView) convertView.findViewById(R.id.vsTeam);
holder.resultsTextView = (TextView) convertView.findViewById(R.id.resultsTextView);
convertView.setTag(holder);
break;
case TYPE_SEPARATOR:
convertView = LayoutInflater.from(mContext).inflate(R.layout.player_section_header, null);
holder.playerNameTextView = (TextView) convertView.findViewById(R.id.lastPlayer);
holder.lastPlayerDate = (TextView) convertView.findViewById(R.id.lastPlayerDate);
convertView.setTag(holder);
break;
}
//convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
switch (rowType){
case TYPE_ITEM:
DecimalFormat formatter = new DecimalFormat("$#,###");
holder.playerNameTextView.setText(player.getName());
holder.playerValueTextView.setText(formatter.format(Double.parseDouble(player.getValue())));
holder.remainingCapTextView.setText(formatter.format(Double.parseDouble(player.getCap())));
holder.username.setText(player.getUsername());
holder.status.setText(player.getStatus());
holder.vsTeamAbbrev.setText(player.getVsTeamAbbrev());
holder.resultsTextView.setText(player.getResultsTextView());
if (player.isMatchMade()) {
holder.status.setVisibility(View.VISIBLE);
}
break;
case TYPE_SEPARATOR:
holder.playerNameTextView.setText(player.getName());
holder.lastPlayerDate.setText(player.getLastPlayerDate());
break;
}
return convertView;
}
private static class ViewHolder {
//item views
TextView playerValueTextView;
TextView playerNameTextView;
TextView remainingCapTextView;
TextView username;
TextView status;
TextView vsTeamAbbrev;
TextView resultsTextView;
//section header views
TextView lastPlayer;
TextView lastPlayerDate;
}
}

adding separators in a listView

I'm trying to add separators between my list view items, I have sorted them into date order and added list entries where the separator needs to go but as soon as it gets to a seperator it stops, no error message or anything it just doesn't add the seperator. I've added breakpoints and it definitely runs the code to add it but it doesn't show up. Even if there are other items to add after the separator it still stops at the separator.
code:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater itemInflater = LayoutInflater.from(getContext());
JourneyItem singleItem = list.get(position);
if(singleItem.isSeperator()){
//set customRow to seperator layout
View customRow = itemInflater.inflate(R.layout.journey_list_seperator, parent, false);
TextView monthText = (TextView) customRow.findViewById(R.id.seperatorMonthText);
TextView yearText = (TextView) customRow.findViewById(R.id.seperatorYearText);
Date current = new Date();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String dtp = GeneralUtil.SQLDateFormatToHuman(list.get(position).getDepartDateTime());
try {
current = df.parse(dtp);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat sdfDate = new SimpleDateFormat("MMMM");
monthText.setText(sdfDate.format(current));
yearText.setText(list.get(position).getDepartDateTime().substring(6,10));
return customRow;
}else {
View customRow = itemInflater.inflate(R.layout.custom_journeyitem_row, parent, false);
TextView titleText = (TextView) customRow.findViewById(R.id.titleDisplay);
TextView fromText = (TextView) customRow.findViewById(R.id.fromLocationDisplay);
TextView departText = (TextView) customRow.findViewById(R.id.departDateTimeDisplay);
TextView toText = (TextView) customRow.findViewById(R.id.toLocationDisplay);
TextView colourLbl = (TextView) customRow.findViewById(R.id.colourDisplay);
titleText.setText(singleItem.getTitle());
fromText.setText("From: " + singleItem.getFromLocation());
departText.setText(singleItem.getDepartDateTime());
toText.setText("To: " + singleItem.getToLocation());
colourLbl.setBackgroundColor(singleItem.getColourCode());
return customRow;
}
Create Coustom adapter like this.
class CustomAdapter extends BaseAdapter {
private static final int TYPE_ITEM = 0;
private static final int TYPE_SEPARATOR = 1;
private ArrayList<String> mData = new ArrayList<String>();
private TreeSet<Integer> sectionHeader = new TreeSet<Integer>();
private LayoutInflater mInflater;
public CustomAdapter(Context context) {
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void addItem(final String item) {
mData.add(item);
notifyDataSetChanged();
}
public void addSectionHeaderItem(final String item) {
mData.add(item);
sectionHeader.add(mData.size() - 1);
notifyDataSetChanged();
}
#Override
public int getItemViewType(int position) {
return sectionHeader.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
}
#Override
public int getViewTypeCount() {
return 2;
}
#Override
public int getCount() {
return mData.size();
}
#Override
public String getItem(int position) {
return mData.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int rowType = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
switch (rowType) {
case TYPE_ITEM:
convertView = mInflater.inflate(R.layout.snippet_item1, null);
holder.textView = (TextView) convertView.findViewById(R.id.text);
break;
case TYPE_SEPARATOR:
convertView = mInflater.inflate(R.layout.snippet_item2, null);
holder.textView = (TextView) convertView.findViewById(R.id.textSeparator);
break;
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(mData.get(position));
return convertView;
}
public static class ViewHolder {
public TextView textView;
}
}
Complete link here.

Android ListView Multiple Row Give Views values in getView method

In getView method i try to set textview text.I have two different type of object. If i use "position" in parameter it gives "IndexOutOfBoundsException" error normally. How can i set text each of them appropriately?
Context context;
ArrayList<OfficialKanal> officialKanals;
ArrayList<NormalKanal> normalKanals;
ArrayList<Object> kanallar = new ArrayList();
int OFFICIAL_KANAL = 0;
int NORMAL_KANAL= 1;
LayoutInflater lala;
public KanalAdapter(Context context , ArrayList<OfficialKanal> officiallar , ArrayList<NormalKanal> normaller){
this.context = context;
officialKanals = officiallar;
normalKanals = normaller;
for(int i = 0 ; i < officiallar.size() ; i++){
kanallar.add(officiallar.get(i));
}
for(int i = 0 ; i < normaller.size() ; i++){
kanallar.add(normaller.get(i));
}
Log.i("tago" , "tagtag");
lala = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return kanallar.size();
}
public Object getItem(int i) {
return kanallar.get(i);
}
public long getItemId(int i) {
return i;
}
public int getItemViewType(int position) {
Object item = getItem(position);
if(item instanceof NormalKanal){
return NORMAL_KANAL;
}else if (item instanceof OfficialKanal){
return OFFICIAL_KANAL;
}
return -1;
}
#Override
public int getViewTypeCount() {
return 2;
}
public View getView(int position, View convertView, ViewGroup viewGroup) {
KanalHolder holder = null;
int pozisyon = 0;
Object currentKanal = getItem(position);
if(convertView==null) {
holder = new KanalHolder();
if (currentKanal instanceof OfficialKanal) {
convertView = lala.inflate(R.layout.officialkanal, null);
holder.image2 = (ImageView) convertView.findViewById(R.id.imageView5);
holder.tv3 = (TextView) convertView.findViewById(R.id.textView4);
holder.tv4 = (TextView) convertView.findViewById(R.id.textView8);
holder.buton2 = (Button) convertView.findViewById(R.id.button7);
holder.buton3 = (Button) convertView.findViewById(R.id.button8);
Log.i("tago", "tagtagatagtagtagatg");
}
if (currentKanal instanceof NormalKanal) {
convertView = lala.inflate(R.layout.normalkanal, null);
holder.image1 = (ImageView) convertView.findViewById(R.id.imageView5);
holder.tv1 = (TextView) convertView.findViewById(R.id.textView4);
holder.tv2 = (TextView) convertView.findViewById(R.id.textView8);
holder.buton1 = (Button) convertView.findViewById(R.id.button8);
Log.i("tago", "tagtagtag");
}
convertView.setTag(holder);
}else{
holder = (KanalHolder)convertView.getTag();
}
if(currentKanal instanceof OfficialKanal){
holder.tv3.setText(officialKanals.get(position).getKanaladi());
}
if(currentKanal instanceof NormalKanal){
holder.tv1.setText(normalKanals.get(position).getKanaladi());
}
return convertView;
}
static class KanalHolder{
public ImageView image1,image2;
public TextView tv1 , tv2,tv3,tv4;
public Button buton1,buton2,buton3;
}
issue is getCount getView will call according to size of kanallar
public int getCount() {
return kanallar.size();
}
but you getting value from officialKanals and normalKanals in getView
try like for experiment
if(currentKanal instanceof OfficialKanal){
holder.tv3.setText(kanallar.get(position).getKanaladi());
}
if(currentKanal instanceof NormalKanal){
holder.tv1.setText(kanallar.get(position).getKanaladi());
}

How to deal with an array item from a spinner?

I need a code to deal with an item in array inside a spinner to allow me to check
.....
if(item == "item name"){
do something
}
or
if(item.position == 1){
do something
}
You can change in adapter like this code
public class PlannedRideAdapter extends BaseAdapter {
// private LayoutInflater mInflater;
private Context context;
private RideData rideData = new RideData();
private List<RideData> ride_data;
public PlannedRideAdapter(Context context, List<RideData> ridedata) {
this.context = context;
this.ride_data = ridedata;
}
#Override
public int getCount() {
if (ride_data.size() > 0) {
return ride_data.size();
}
return 1;
}
#Override
public Object getItem(int arg0) {
return arg0;
}
#Override
public long getItemId(int arg0) {
return arg0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewholder;
if (convertView == null) {
LayoutInflater inflator = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflator.inflate(R.layout.plannedride_km_list, null);
viewholder = new ViewHolder();
convertView.setTag(viewholder);
} else {
viewholder = (ViewHolder) convertView.getTag();
}
rideData = ride_data.get(position);
// init view
viewholder.imageView = (ImageView) convertView
.findViewById(R.id.imageView1);
viewholder.date = (TextView) convertView.findViewById(R.id.date_value);
viewholder.source = (CustomFontTextView) convertView
.findViewById(R.id.source_icon);
viewholder.time = (TextView) convertView.findViewById(R.id.time_value);
viewholder.destination = (CustomFontTextView) convertView
.findViewById(R.id.dest_icon);
viewholder.rideId = (CustomFontTextView) convertView
.findViewById(R.id.rideId);
viewholder.ride_id = (TextView) convertView
.findViewById(R.id.rideIdText);
viewholder.distance = (CustomFontTextView) convertView
.findViewById(R.id.distance);
viewholder.source_value = (TextView) convertView
.findViewById(R.id.source_value);
viewholder.ride_id_value = (TextView) convertView
.findViewById(R.id.rideId_value);
viewholder.distance_value = (TextView) convertView
.findViewById(R.id.distance_value);
// viewholder.ride_detail = (TextView) convertView
// .findViewById(R.id.textRideDetail);
// setview
viewholder.date.setText("" + rideData.getDate());
viewholder.source.setText(context.getResources().getString(
R.string.font_awesome_marker_icon));
viewholder.source_value.setText("" + rideData.getSource());
viewholder.time.setText("" + rideData.getTime());
viewholder.rideId.setText(context.getResources().getString(
R.string.font_awesome_bookingnumber_icon));
viewholder.ride_id_value.setText("" + rideData.getRideId());
if (rideData.getRideType().equalsIgnoreCase("k")) {
viewholder.distance.setVisibility(View.VISIBLE);
viewholder.distance_value.setVisibility(View.VISIBLE);
viewholder.imageView.setImageResource((R.drawable.one_way));
viewholder.destination.setText(context.getResources().getString(
R.string.font_awesome_radio_tick_icon));
viewholder.distance.setText(context.getResources().getString(
R.string.font_awesome_distance_icon));
viewholder.distance_value.setText(""
+ rideData.getKilometerRide().getDestination());
} else {
viewholder.imageView.setImageResource((R.drawable.time));
viewholder.destination.setText(context.getResources().getString(
R.string.font_awesome_clock_icon));
viewholder.distance.setVisibility(View.GONE);
viewholder.distance_value.setVisibility(View.GONE);
// viewholder.ride_detail.setVisibility(View.GONE);
}
return convertView;
}
public List<RideData> getRide_data() {
return ride_data;
}
public void setRide_data(List<RideData> ride_data) {
this.ride_data = ride_data;
}
public static class ViewHolder {
public CustomFontTextView source;
public CustomFontTextView destination;
public CustomFontTextView rideId;
public CustomFontTextView distance;
public CustomFontTextView total_time;
public TextView date, time, distance_value, source_value,
destination_value, time_value, ride_id_value, ride_id;
public ImageView imageView;
}
}
I am showing list based on kilometer(rideType k) or hourly (rideType h) with same layout.

How to create listview for displaying sender receiver messages using baseadapter?

when we scroll down or up getview problem?
getview not called properly?
at background images are loading from respective url?
layout is different for sender and receiver..
public class NewReadMessageAdapter extends BaseAdapter {
private Context context;
private LayoutInflater vi;
public ImageLoader imageLoader;
private Typeface tf;
private class Image {
String pic_url = new String();
Bitmap thumb;
String messege = new String();
int id;
String time = new String();
String sender_name = new String();
public boolean sender_user;
}
private Image[] images;
ArrayList<Messages> messages = new ArrayList<Messages>();
private TextView txt_msg;
private TextView txt_name;
private TextView txt_time;
Button btn_loc;
private ImageView img;
private ArrayList<Messages> mData = new ArrayList<Messages>();
private TreeSet<Integer> mSeparatorsSet = new TreeSet<Integer>();
private static final int TYPE_RECEIVER = 0;
private static final int TYPE_SENDER = 1;
public NewReadMessageAdapter(Context context,
ReadMessagePostParser messageParser, String sender_id,
String reciever_id) {
this.context = context;
tf = Typeface.createFromAsset(context.getAssets(), "fonts/tahoma.ttf");
messages = messageParser.getMessages();
imageLoader = new ImageLoader(context.getApplicationContext());
images = new Image[messages.size()];
for (int i = 0, j = messages.size(); i < j; i++) {
images[i] = new Image();
images[i].messege = messages.get(i).getMessage_text();
images[i].time = messages.get(i).getTime();
if (messages.get(i).getMessage_from().equals("YES")) {
images[i].sender_name = messageParser.sender_name;
images[i].pic_url = messageParser.sender_pic_url;
images[i].sender_user = true;
images[i].id = Integer.parseInt(sender_id);
} else {
images[i].sender_user = false;
images[i].id = Integer.parseInt(reciever_id);
images[i].sender_name = messageParser.reciever_name;
images[i].pic_url = messageParser.receiver_pic_url;
}
}
for (int i = 0; i < images.length; i++) {
System.out.println(images[i].pic_url + " " + images[i].sender_name
+ " " + images[i].messege);
}
vi = LayoutInflater.from(context);
imageLoader = new ImageLoader(context.getApplicationContext());
}
public void addItem(final Messages item) {
mData.add(item);
notifyDataSetChanged();
}
public void addSeparatorItem(final Messages item) {
mData.add(item);
mSeparatorsSet.add(mData.size() - 1);
notifyDataSetChanged();
}
#Override
public int getCount() {
return mData.size();
}
#Override
public Object getItem(int position) {
return mData.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public int getItemViewType(int position) {
return mSeparatorsSet.contains(position) ? TYPE_SENDER : TYPE_RECEIVER;
}
#Override
public View getView( int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int type = getItemViewType(position);
if (convertView == null) {
switch (type) {
case TYPE_SENDER:
System.out.println("Sender");
holder = new ViewHolder();
convertView = vi.inflate(R.layout.list_row_layout_sender, null);
holder.txt_msg = (TextView) convertView
.findViewById(R.id.txt_msg);
holder.txt_name = (TextView) convertView
.findViewById(R.id.txt_name);
holder.txt_time = (TextView) convertView
.findViewById(R.id.txt_time);
holder.img = (ImageView) convertView
.findViewById(R.id.user_img);
holder.btn_loc = (Button) convertView
.findViewById(R.id.btn_loc);
convertView.setTag(holder);
break;
case TYPE_RECEIVER:
System.out.println("Receiver");
convertView = vi.inflate(R.layout.list_row_layout_receiver, null);
holder = new ViewHolder();
holder.txt_msg = (TextView) convertView
.findViewById(R.id.txt_msg);
holder.txt_name = (TextView) convertView
.findViewById(R.id.txt_name);
holder.txt_time = (TextView) convertView
.findViewById(R.id.txt_time);
holder.img = (ImageView) convertView
.findViewById(R.id.user_img);
holder.btn_loc = (Button) convertView
.findViewById(R.id.btn_loc);
convertView.setTag(holder);
break;
}
} else {
holder = (ViewHolder)convertView.getTag();
}
holder.btn_loc.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
System.out
.println("-------------- btn_loc ------------------- Sender");
Developer.callIntent_userlocation(context, "18.50929796 ",
"73.79045371");
}
});
holder.txt_name.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("----Name----");
}
});
holder.img.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("----Image----");
}
});
holder.txt_name.setText(mData.get(position).message_from);
holder.txt_time.setText(mData.get(position).time);
holder.txt_msg.setText(mData.get(position).message_text);
if (position != 0) {
cached = images[position - 1];
if (cached.sender_user == flag) {
holder.img.setVisibility(ImageView.INVISIBLE);
holder.txt_name.setVisibility(TextView.INVISIBLE);
} else
imageLoader.DisplayImage(images[position].pic_url.trim()
.replace(" ", "%20"), ReadMessageActivityNew.activity,
holder.img);
} else
imageLoader.DisplayImage(
images[position].pic_url.trim().replace(" ", "%20"),
ReadMessageActivityNew.activity, holder.img);
return convertView;
}
static class ViewHolder {
TextView txt_msg;
TextView txt_name;
TextView txt_time;
ImageView img;
Button btn_loc;
}
}
It is better to reuse convertView only when both the layouts are the same. As the layouts are different here, when you reuse a convertView used by sender for receiver, then the view may not be as expected.

Categories

Resources