android mapview problem - android

I want to show a simple text view on map view pushpin.on click of that pushpin i want to show the detail info.
when user taps on specific point i want to show name of that point..these name I'm storing in POJO class and i want to retrieve from that,now in my code I'm successfully getting names but only problem is names are not displaying on that particulate tap point.
Please Help...
here is my code....
#Override
public boolean onTap(GeoPoint p, MapView mapView) {
str.
final PopupWindow popupWindow;
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.popup, (ViewGroup) findViewById(R.id.rootId));
TextView text = (TextView)layout.findViewById(R.id.nameTextView);
text.setText("Lake Name");
text.setBackgroundColor(Color.BLACK);
popupWindow=new PopupWindow(layout);
popupWindow.setTouchable(true);
popupWindow.setWidth(LayoutParams.WRAP_CONTENT);
popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(layout,Gravity.CENTER_HORIZONTAL,10,0);
builder=new AlertDialog.Builder(DummyLocationActivity.this);
text.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
popupWindow.dismiss();
LayoutInflater inflater=LayoutInflater.from(DummyLocationActivity.this);
View desc= inflater.inflate(R.layout.description,(ViewGroup) findViewById(R.id.root));
builder.setView(desc);
builder.show();
}
});
return true;
}

OnTap(int position) you can get the particular item on tap by using the position .

Related

Showing a custom Toast positioned into ListView Item position

I'm trying to show a custom toast exactly into deleted ListView item position. This is all I could do:
Adapter:
private View.OnClickListener onDeleteListener(final int position, final ViewHolder holder) {
return new View.OnClickListener() {
#Override
public void onClick(View v) {
showCustomToast(position, position);
}
};
}
public void showCustomToast(int positionX, int positionY) {
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.toast_layout, null, false);
ImageView icon = (ImageView) layout.findViewById(R.id.toast_image);
TextView message = (TextView) layout.findViewById(R.id.toast_text);
LinearLayout fundoMensagem = (LinearLayout) layout.findViewById(R.id.toast_root);
message.setTextColor(Color.BLACK);
fundoMensagem.setBackgroundResource(R.color.error_colors);
message.setText("Item Deleted!");
Toast toast = new Toast(context);
toast.setDuration(toast.LENGTH_LONG);
toast.setView(layout);
toast.setGravity(positionX, positionX, positionX);
toast.show();
}
But this isn't exactly what I need because the position variable of the onDeleteListener method only get the item index and not the screen position. Someone can help me to show the custom toast at the center of each listview item?
You could use View.getLocationOnScreen() and/or getLocationInWindow() to get the absolute coordinates of a view on the screen, but I don't think a Toast is the right things to be putting there, Toasts are system level notifications, not app level, so it would be a bit of a stretch to try to force it into a position in your app. I think you would be much better served by some sort of custom view.

How to get the text value of a button and load it into another button in Android

I am creating a word game application , I have created a grid view consisting of buttons. When I click a button in the grid view a popup windows opens which contains all the English alphabets.Now when I click any letter in my pop up window , I want that letter to appear in my grid that is the string in my pop window's button must appear in my grid view's button. , how do I do it?
This is my button's code:
button1.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v) {
layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View container = layoutInflater.inflate(R.layout.activity_popup,null);
popupWindow = new PopupWindow(container,800,1100,true);
popupWindow.showAtLocation(constraintLayout, Gravity.NO_GRAVITY,150,400);
b1=(Button) findViewById(R.id.b1);
String s1 = b1.getText().toString();
button1.setText(s1);
container.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionevent){
popupWindow.dismiss();
return true;
}
});
}
});
My popup window's code:
b1.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
String s1 = "A";
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
}
});
Screenshots of the app
This is my grid layout where the user must enter the letters
When I click any button on the grid this is the pop up window which is displayed.
If I run this , the app is getting stopped.
It might help us if you would share the exact exception that is thrown by your application.
If I unterstand you correctly, then b1 is a button contained in your activity_popup- layout. So you might want to try b1 = (Button) container.findViewById(R.id.b1) instead. If thats not working, post your exception!

Popup window on a ListView Android

I have created a custom arrayadapter for my listview. It has a player name and the score, I also have a add button on the cell, when that button is clicked I want a popup screen to appear, Here is where the user can add the score of the player. This popup window has 6 buttons "+1", "+2" "+10" ..etc and a done button. When the done button is clicked the score gets updated.
I am handling the add button click event on my customArraryAdapter class, so I have to create the popup here as well. I have searched and tried to do this with no success.
What I tried so far:
I have a View = convertView and a viewHolder = holder The problem is I'm not so sure what to pass as the parameter to create a popup. The code below is myCustomArrayAdapter class. I have also read popups cant handle touch events, but some are saying it can. Since my popup has a lot of buttons maybe this might be a great solution.
This is in #Override
public View getView(final int position, View convertView, ViewGroup parent) Method in CustomArrayAdapter Class
//Handle add button click
holder.add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
addScores(convertView);
//list gets updated
notifyDataSetChanged();
}
});
My addScores method looks like this
private void addScores(View v){
PopupWindow pw;
LayoutInflater inflater = (LayoutInflater)v.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.weight_popup, (ViewGroup)v.findViewById(R.id.linlay_weight_popup));
pw = new PopupWindow(layout, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.setOutsideTouchable(true);
pw.showAsDropDown(btnSelectWeight);
}
You may pass View that will be displayed in popup the same way you do.
Consider this:
View layout = inflater.inflate(R.layout.weight_popup, (ViewGroup)v.findViewById(R.id.linlay_weight_popup));
Your weight_popup layout should contain 6 buttons, which would have onClick there you update scores.
Something like:
Button btn1 = (Button)layout.findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//update your score here.
}
});
//other buttons..
pw = new PopupWindow(layout, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);

How to customize appearence of android google maps api v2 info window?

In my android app, I have a info window for a marker I place on the map. I want to do these things:
Make the default marker bigger (its too small now)
When the info window shows up, the text in it is making the width too long. Is there a way I can set a maximum width on it?
How can I increase the font size for the title and text?
Can anyone show me how to do this?
Thanks.
Maybe a little late, but you need to create a new custom adapter you can take a look in here: How to change Google Maps marker window Info
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
#Override
public View getInfoWindow(com.google.android.gms.maps.model.Marker arg0) {
return null;
}
#Override
public View getInfoContents(com.google.android.gms.maps.model.Marker marker) {
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View mView = null;
//using the id, you can store multiple types of markers on List's and change the layout
if (marker.getId().equals(end.getId())) {
mView = inflater.inflate(R.layout.custom_info_window, (ViewGroup) findViewById(R.id.map), false);
((TextView) mView.findViewById(R.id.txtTitle)).setText(marker.getTitle());
}else{
mView = inflater.inflate(R.layout.normal_info_window, (ViewGroup) findViewById(R.id.map), false);
((TextView) mView.findViewById(R.id.txtTitle)).setText(marker.getTitle());
((TextView) mView.findViewById(R.id.txtDescription)).setText(marker.getSnippet());
}
return mView;
}
});
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker marker) {
//do whatever you need
}
});
In te custom view you can modify the size of the font, and other things, for the first point the marker icon can be modified on the MarkerOptions.setIcon, where you can use one from your assets.
1: When you add the Marker to the map, you can set the icon in the MarkerOptions. Make your own icon and use that.
2 & 3: Set an onMarkerClickListener on your GoogleMap. In the callback, you can create and show your own info window view on the map (just make sure you return false from the onMarkerClick() callback)

setClickable() is not working on button

I want to make button unclickable using setClicable() but it's not working. I am using inflater because I need.
This is my code:
mContactList = (LinearLayout) findViewById(R.id.contactList);
LayoutInflater inflater = getLayoutInflater();
for (ListIterator<ContactModel> it = contactList.listIterator(); it.hasNext();){
ContactModel contact = it.next();
View view = inflater.inflate(R.layout.contact_unknown_list_row, null);
view.findViewById(R.id.inviteButton).setTag(contact.getEmail());
view.findViewById(R.id.inviteButton).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String address = (String) v.getTag();
sendInvatoin(address);
if(v.findViewById(R.id.inviteButton).isClickable())
v.findViewById(R.id.inviteButton).setClickable(false);
}
});
mContactList.addView(view);
}
Try using.
button.setEnabled(false);
In your case, you will do something like this:
view.findViewById(R.id.inviteButton).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String address = (String) v.getTag();
sendInvitatoins(address);
Button b = (Button)v;
b.setEnabled(false);
}
});
When using setOnClickListener, unclickable views (= v.setClickable(false)) would become clickable as mentioned in Docs.
... a callback to be invoked when this view is clicked. If this
view is not clickable, it becomes clickable.
Better to use v.setEnabled(false) if you want to set an OnClickListener to the button or any other view...
This will work in case of Imageview as well as the button.
private OnClickListener onClickListener = new OnClickListener() {
#Override
public void onClick(View v) {
if (imageview.isEnabled()){
//I have wrapped all code inside onClick() in this if condition
//Your onClick() code will only execute if the imageview is enabled
//Now we can use setEnabled() instead of setClickable() everywhere
}}
};
Inside onCreate(), you can do setEnabled(false) which will be equivalent to setClickable(false).
We are able to use setEnabled() as tag because it's state remains unaffected on invocation of click (unlike setClickable() whose state changes).

Categories

Resources