Android : Access elements in ListView populated with BaseAdapter - java

I am working on an Android project in which I am currently working on chat functionality. Now, whenever an user sends a message, it is added in the ListView, which is populated by BaseAdapter. A new message is added by baseAdapterObject.add(item);.
Now, whenever an user sends a message, I am adding it directly to the already existing List and then waiting for a reply from the server confirming the message was delivered. For the first step, I would like to show a Gray checkmark, and for 2nd message received from server, I would like to show Blue checkmark.
Unfortunately, I don't know how to access the already populated list and change the background image of an ImageView. . Each message has a random-number, with which I can compare for which message I received confirmation.
Code :
public void recieveUpdatedMessageFromServer(String channelName, Map<String, Object> input){
String randomNumberFromServer = ((Map) input.get("data")).get("random").toString();
if (randomNumberFromServer.equals(randomNos)) {
messageRecieved = true;
randomNos = "";
}
chatMessagesAdapter.add(insertMap);
runOnUiThread(new Runnable() {
#Override
public void run() {
chatMessagesAdapter.notifyDataSetChanged();
}
});
public class ChatMessagesAdapter extends BaseAdapter {
private Activity activity = null;
private ArrayList<HashMap<String, String>> data;
private LayoutInflater inflater = null;
public ChatMessagesAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data = d;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void add(HashMap<String, String> item) {
data.add(item);
}
#Override
public int getCount() {
return data.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.chat_messages_row, parent, false);
TextView chatText = (TextView) vi.findViewById(R.id.chatText);
ImageView userImage = (ImageView) vi.findViewById(R.id.chatImage);
TextView firstName = (TextView) vi.findViewById(R.id.personName);
ImageView checkMark = (ImageView) vi.findViewById(R.id.checMarkChat);
HashMap<String, String> chatList;
chatList = data.get(position);
chatText.setText(chatList.get(ChatMessagesActivity.chatText));
checkMark.setBackgroundResource(R.drawable.blue_icon);
firstName.setText(chatList.get(ChatMessagesActivity.firstName));
if (!(chatList.get(ChatMessagesActivity.chatImageId).equals("0"))) {
Picasso.with(context).load(StaticRestTemplate.baseURL + "image/" + chatList.get(ChatMessagesActivity.chatImageId)).fit().into(userImage);
}
return vi;
}
}
}
chat_messages_row.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="130dp"
android:orientation="horizontal"
android:padding="2.5dip">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="125dp"
android:id="#+id/frameLayout2">
<ImageView
android:id="#+id/chatImage"
android:layout_width="107dp"
android:layout_height="107dp"
android:padding="2dp" />
</FrameLayout>
<TextView
android:id="#+id/chatText"
android:layout_width="230dp"
android:layout_height="76dp"
android:layout_gravity="right|center_vertical"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/frameLayout2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/personName"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/chatText"
android:layout_alignEnd="#+id/chatText"
android:layout_toRightOf="#+id/textView"
android:layout_toEndOf="#+id/textView"
/>
<ImageView
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/checMarkChat"
android:background="#drawable/blue_icon"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/personName"
android:layout_alignEnd="#+id/personName" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="49dp"
android:layout_marginStart="49dp"
android:layout_marginTop="208dp" />
</RelativeLayout>
I hope this much information is enuf. Kindly let me know if anything else required. Thank you. :-)

Consider using a class object to help.
For example, you can create a list of message objects:
class Message {
private String message;
private boolean gray_tick;
private boolean blue_tick;
....
}
Change your hashmap in your BaseAdapter to take in the corresponding object.
private ArrayList<HashMap<String, Message>> data;
From there, you can set your BaseAdapter to read these values and show the correct coloured ticks at the right time.
Hope this helps!

Related

CustomAdapter Not Showing Data

I am trying to retrieve data from parse,therefore I need to make a custom adapter for the listview but its not working,I created a custom adapter but the listview is not showing and I can't figure out what is the problem.
I am getting no errors or crashes so I can't point the exact problem.
This is what I have done:
The adapter:
public class MyListView extends BaseAdapter {
private final ArrayList<HashMap<String, String>> contentList;
private static LayoutInflater inflater = null;
public MyListView(Activity a, ArrayList<HashMap<String, String>> contentForList) {
this.contentList = contentForList;
inflater = (LayoutInflater) a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return contentList.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.mylist, null);
ImageView logo = (ImageView) vi.findViewById(R.id.icon); // title
TextView titleText = (TextView) vi.findViewById(R.id.title); // artist name
TextView subtitleText = (TextView) vi.findViewById(R.id.subtitle);
HashMap<String, String> info = new HashMap<String, String>();
info = contentList.get(position);
String title = (String) info.get("businessname");
String peopleinBusiness = (String) info.get("peopleinbusiness");
// Setting all values in listview
titleText.setText(title);
subtitleText.setText(peopleinBusiness);
// Bitmap bmp = (Bitmap) info.get("photo");
// logo.setImageBitmap(bmp);
return vi;
}
}
listView XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp" />
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:textColor="#4d4d4d" />
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginLeft="10dp"/>
</LinearLayout>
</LinearLayout>
MainActivity:
ArrayList<HashMap<String,String>> feedData = new ArrayList<>();
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.orderByDescending("createdAt");
query.setLimit(20);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null){
for (ParseObject feed : objects){
HashMap<String, String> PlacesInfo = new HashMap<>();
PlacesInfo.put("username",feed.getString("username"));
PlacesInfo.put("worthcomming",feed.getString("worthcomming"));
PlacesInfo.put("businessname",feed.getString("BusinessName"));
PlacesInfo.put("peopleinbusiness",feed.getString("PeopleInBusiness"));
feedData.add(PlacesInfo);
}
MyListView listview = new MyListView(FeedActivity.this,feedData);
feedListView.setAdapter(listview);
listview.notifyDataSetChanged();
}else{
Log.e("findinBackground","Failed");
e.printStackTrace();
}
}
});
Thank you !!
I can't believe I spend so much time only to figure out I was missing a " _ " .
I changed this:
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
To this:
ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
Thank everyone !

Show icons only in drop-down of custom Spinner

I Have created a Spinner using adapter with icons and text. Everything is displayed correctly but there is a requirement that Activity spinner should show text only. Icons should only appear in the drop-down list.
It this possible to implement?
public class CustomAdapter extends BaseAdapter {
Context context;
int flags[];
String[] countryNames;
LayoutInflater inflter;
public CustomAdapter(Context applicationContext, int[] flags, String[] countryNames) {
this.context = applicationContext;
this.flags = flags;
this.countryNames = countryNames;
inflter = (LayoutInflater.from(applicationContext));
}
[id3844467|#Override]
public int getCount() {
return flags.length;
}
[id3844467|#Override]
public Object getItem(int i) {
return null;
}
[id3844467|#Override]
public long getItemId(int i) {
return 0;
}
[id3844467|#Override]
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflter.inflate(R.layout.custom_spinner_items, null);
ImageView icon = (ImageView) view.findViewById(R.id.imageView);
TextView names = (TextView) view.findViewById(R.id.textView);
icon.setImageResource(flags[i]);
names.setText(countryNames[i]);
return view;
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="5dp"
android:src="#drawable/ic_launcher" /> // for check that icon existing
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="0dp"
android:text="Demo" // for check that text existing
android:textColor="#000" />
</LinearLayout>
Set these two property in spinner hopeFully it will work
android:dropDownHeight="0dp"
android:dropDownWidth="0dp"
i'am not sure but change your getItemId like this :
#Override
public long getItemId(int position) {
return position;
}
and don't return null on getItem

Android Studio ListView Checkbox Save

Ive looked at a few other questions on stackoverflow about this questions however I am not able to implement this into my code as I have done things a bit differently I believe. I am still learning Android Studio so please bear with me for any stupidity.
I'm looking to create check boxes on the right side of the listview I currently have that when checked will stay in that state when the user loads the application back in.
XML:
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Which Will Be Next"
android:textAllCaps="false"
android:textColor="#f1b75a"
android:textSize="32sp"
android:textStyle="bold" />
<ListView
android:id="#+id/results_listview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/textView3"></ListView>
</RelativeLayout>
Activity Code:
public class .... extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_flavour);
ListView resultListView = (ListView) findViewById(R.id.results_listview);
HashMap<String, String> nameAddress = new HashMap<>();
nameAddress.put("exmp ", "Locate");
List<HashMap<String, String>> listItems = new ArrayList<>();
SimpleAdapter adapter = new SimpleAdapter(this, listItems, R.layout.list_item, new String[]{"First Address", "Second Address"},new int[]{R.id.tv1, R.id.tv3});
Iterator it = nameAddress.entrySet().iterator();
while (it.hasNext()){
HashMap<String, String> resultsMap = new HashMap<>();
Map.Entry pair = (Map.Entry)it.next();
resultsMap.put("First Address", pair.getKey().toString());
resultsMap.put("Second Address", pair.getValue().toString());
listItems.add(resultsMap);
}
resultListView.setAdapter(adapter);
}
}
List Items.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckedTextView
android:id="#+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffa200"
android:textSize="21sp"
android:textStyle="bold"
android:drawableLeft="?android:attr/listChoiceIndicatorMultiple"
/>
<CheckedTextView
android:id="#+id/tv3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold"
/>
</LinearLayout>
Any help is appreciated :)
I suggest the you can use Recyclerview instead listview, Try this way
public class CardViewDataAdapter extends
RecyclerView.Adapter<CardViewDataAdapter.ViewHolder> {
private List<Student> stList;
public CardViewDataAdapter(List<Student> students) {
this.stList = students;
}
// Create new views
#Override
public CardViewDataAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
// create a new view
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
R.layout.cardview_row, null);
// create ViewHolder
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
#Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
final int pos = position;
viewHolder.tvName.setText(stList.get(position).getName());
viewHolder.tvEmailId.setText(stList.get(position).getEmailId());
viewHolder.chkSelected.setChecked(stList.get(position).isSelected());
viewHolder.chkSelected.setTag(stList.get(position));
viewHolder.chkSelected.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
Student contact = (Student) cb.getTag();
contact.setSelected(cb.isChecked());
stList.get(pos).setSelected(cb.isChecked());
Toast.makeText(
v.getContext(),
"Clicked on Checkbox: " + cb.getText() + " is "
+ cb.isChecked(), Toast.LENGTH_LONG).show();
}
});
}
// Return the size arraylist
#Override
public int getItemCount() {
return stList.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView tvName;
public TextView tvEmailId;
public CheckBox chkSelected;
public Student singlestudent;
public ViewHolder(View itemLayoutView) {
super(itemLayoutView);
tvName = (TextView) itemLayoutView.findViewById(R.id.tvName);
tvEmailId = (TextView) itemLayoutView.findViewById(R.id.tvEmailId);
chkSelected = (CheckBox) itemLayoutView
.findViewById(R.id.chkSelected);
}
}
// method to access in activity after updating selection
public List<Student> getStudentist() {
return stList;
}
}
http://android-pratap.blogspot.in/2015/01/recyclerview-with-checkbox-example.html

How can i display images and videos (from app resources) repeatedly on the app without stick the UI

I need to do app like slideshow of images and vidoes from fiels from the device.
I have tried several projects - but no one can display videos.
What is the best way to do ot. All I need is to display, repeatedly, images and videos from the devices without the UI will stuck
There are some of the projects that i tried:
https://github.com/daimajia/AndroidImageSlider
https://github.com/marvinlabs/android-slideshow-widget
Thank you
I am showing a list of videos:
The Activity code:
public class VideoListActivity extends AppCompatActivity {
private ListView lvVideos;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_list);
lvVideos = (ListView)findViewById(R.id.lvVideos);
lvVideos.setAdapter(new VideosListAdapter(this));
}
}
The adapter code:
public class VideosListAdapter extends BaseAdapter {
private static LayoutInflater inflater = null;
private ArrayList<VideoData> listVideoData = new ArrayList<>();
private String[] creationDates = new String[0];
public VideosListAdapter(VideoListActivity videoListActivity) {
inflater = (LayoutInflater) videoListActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// here is a listVideoData and the creationDates initialisation code.
}
#Override
public int getCount() {
return listVideoData.size();
}
#Override
public Object getItem(int position) {
return listVideoData.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (vi == null) {
vi = inflater.inflate(R.layout.row_video, null);
}
VideoData videoData = listVideoData.get(position);
VideoView videoView = (VideoView)vi.findViewById(R.id.videoView);
videoView.setVideoPath(videoData.getVideoFilePath());
TextView tvDate = (TextView) vi.findViewById(R.id.tvDate);
tvDate.setText(creationDates[position]);
TextView tvInfo = (TextView) vi.findViewById(R.id.tvPuppetInfo);
tvInfo.setText("Whatever you want" );
// must add this: -otherwise I don't know why, but is not working the click
RelativeLayout relativeLayout = (RelativeLayout)videoView.getParent();
relativeLayout.setClickable(true);
relativeLayout.setOnClickListener(rlClickListener);
return vi;
}
View.OnClickListener rlClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
VideoView videoView = (VideoView)v.findViewById(R.id.videoView);
videoView.start();
}
};
}
A code part in the row_video.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<!-- Yes, it is in pixel, hardcoded, because this is what is requested -->
<VideoView
android:id="#+id/videoView"
android:layout_width="1280px"
android:layout_height="720px"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/tvDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/videoView"
android:layout_below="#+id/videoView"
android:layout_marginTop="5dp"
android:focusable="false"
android:text="25/12/2016 12:59:59"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<TextView
android:id="#+id/tvStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/videoView"
android:layout_below="#+id/videoView"
android:layout_marginTop="5dp"
android:drawableRight="#drawable/red_check"
android:text="whatever you want"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="#+id/tvInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/videoView"
android:layout_centerHorizontal="true"
android:layout_marginTop="1dp"
android:gravity="center"
android:layout_toLeftOf="#+id/tvStatus"
android:layout_toRightOf="#+id/tvDate"
android:focusable="false"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
I hope it worth an upvote ! ( click )

Multiple InfoWindows Android Maps V2

So my application requires me to create a route for a certain bus. I have accomplished this and have created a custom info window for the marker. Now, I was asked to add a feature in which I need to show on the map POIs (points of interests) around the marker. I have successfully created this. However, I want a different Info window for these POI markers.
Here is my first info window:
public class InfoAdapter implements GoogleMap.InfoWindowAdapter {
LayoutInflater inflater = null;
private TextView textViewstopName;
private TextView arrivalTime;
public InfoAdapter(LayoutInflater inflater) {
this.inflater = inflater;
}
#Override
public View getInfoWindow(Marker marker) {
View v = inflater.inflate(R.layout.businfo_layout, null);
if (marker != null) {
textViewstopName = (TextView) v.findViewById(R.id.businfo);
textViewstopName.setText(marker.getTitle());
arrivalTime = (TextView) v.findViewById(R.id.arrivalinfo);
arrivalTime.setText(marker.getSnippet());
}
return (v);
}
#Override
public View getInfoContents(Marker marker) {
return (null);
}
}
And here is my second one (I wanted to have to default one for the POIs for now):
public class PlacesAdapter implements GoogleMap.InfoWindowAdapter{
LayoutInflater inflater = null;
public PlacesAdapter(LayoutInflater inflater) {
this.inflater = inflater;
}
#Override
public View getInfoWindow(Marker marker) {
return null;
}
#Override
public View getInfoContents(Marker marker) {
return null;
}
}
Here is where I called the first one:
private void SetupStopMarkers(){
map.setInfoWindowAdapter(new InfoAdapter(getLayoutInflater()));
addMarkersToMap(markerPoints);
}
Here is where I called the second one:
else{
map.setInfoWindowAdapter(new PlacesAdapter(getLayoutInflater()));
...
}
My info_layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1"
android:background="#drawable/businfo_dialog">
<ImageView
android:id="#+id/busicon"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/busstop_icon"/>
<ImageView
android:id="#+id/clockicon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#+id/busicon"
android:layout_alignParentLeft="true"
android:paddingLeft="5dp"
android:src="#drawable/clock"
android:paddingBottom="10dp"/>
<TextView
android:id="#+id/businfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFFFF"
android:drawablePadding="10dp"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/busicon"
android:layout_toEndOf="#+id/busicon"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/arrivalinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFFFF"
android:drawablePadding="10dp"
android:layout_centerVertical="true"
android:layout_below="#+id/businfo"
android:layout_toRightOf="#+id/clockicon"
android:layout_toEndOf="#+id/clockicon"
android:paddingRight="10dp"
android:paddingTop="5dp"/>
<TextView
android:id="#+id/placesinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/arrivalinfo"
android:paddingTop="5dp"
android:paddingBottom="35dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#0099cc"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="#string/more_info"/>
<TextView
android:id="#+id/eta_i"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/arrivalinfo"
android:layout_toEndOf="#+id/arrivalinfo"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:layout_alignTop="#+id/arrivalinfo"
android:text="ETA:"
android:textStyle="bold"
android:textColor="#FFFFFFFF"/>
</RelativeLayout>
But after calling the second info window, every marker in the map changes to that second info window. Is there a way to do this? Any help is appreciated.
Got it. So to get multiple Info windows, I had to get the marker ids corresponding to the markers. So I created a ArrayList that takes in the "id" of the marker.
ArrayList<String> markerPlaces = new ArrayList<>();
I then populated it as I add the markers to the map:
Marker marker = map.addMarker(new MarkerOptions().position(position)
.title(venuesfound.get(i).getName())
.snippet("\nOpen: " + venuesfound.get(i).getOpenNow()
+ "\n(" + venuesfound.get(i).getCategory() + ")")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.measle_blue)));
markerPlaces.add(marker.getId());
Then on the InfoAdapter, I just added a condition that if the marker id is in the ArrayList that I created, then put in a different inflater.
public class InfoAdapter implements GoogleMap.InfoWindowAdapter {
LayoutInflater inflater = null;
private TextView textViewstopName;
private TextView arrivalTime;
public InfoAdapter(LayoutInflater inflater) {
this.inflater = inflater;
}
#Override
public View getInfoWindow(Marker marker) {
if (marker != null) {
if(markerPlaces.containsKey(marker.getId())) {
... //Add new inflater here.
} //checks if the marker is part of the Position marker or POI marker.
else{
View v = inflater.inflate(R.layout.businfo_layout, null);
textViewstopName = (TextView) v.findViewById(R.id.businfo);
textViewstopName.setText(marker.getTitle());
arrivalTime = (TextView) v.findViewById(R.id.arrivalinfo);
arrivalTime.setText(marker.getSnippet());
return (v);
}
}
return null;
}
#Override
public View getInfoContents(Marker marker) {
return (null);
}
}
Thank you all for the help! It certainly got me thinking!

Categories