【发布时间】:2016-05-06 09:19:32
【问题描述】:
我有一个函数,它实际上将名称设置到文本视图中,并且我有一个按钮侦听器,它实际上是在 oncreate 方法中定义的。所有名称都有一个唯一的对象 id。我需要将所选名称的对象 ID 获取到按钮的 onclick 函数中,并且该对象 ID 通过捆绑附加功能将意图传递给下一个活动。该函数在 oncreate 方法之外定义。所有名称和相应的 ID正在通过网络服务调用。
设置文本视图的功能是
public void setMarker(){
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
SaloonDetails = "";
// Take some action here
String snippet = marker.getSnippet();
objectId = snippet;
if (selectedMarker != null && !("currentLocation".equals(snippet))) {
selectedMarker.setIcon(BitmapDescriptorFactory.fromResource(R.mipmap.map_red));
}
selectedMarker = marker;
if (!("currentLocation".equals(snippet)))
marker.setIcon(BitmapDescriptorFactory.fromResource(R.mipmap.map_blue));
Log.i("TAG", "snippet::::" + snippet);
if ("currentLocation".equals(snippet)) {
selectedLayout.setVisibility(View.GONE);
//button_bookmark.setVisibility(View.GONE);
return false;
} else {
selectedLayout.setVisibility(View.VISIBLE);
TextView nameView = ((TextView) selectedLayout
.findViewById(R.id.name_txt_id));
TextView addressView = ((TextView) selectedLayout
.findViewById(R.id.address_txt_id));
Button button = ((Button) selectedLayout
.findViewById(R.id.selec_button_id));
try {
JSONObject jSalonData = (JSONObject)SalonData.get(snippet);
nameView.setText(jSalonData.getString("SalonName"));
// button.setText(jSalonData.getString("SalonName"));
String Slecteditem1= nameView.getText().toString();
Log.i("Sltitem olemapsAivity",Slecteditem1);
} catch (Exception e) {
e.printStackTrace();
}
try {
JSONObject jSalonData = (JSONObject)SalonData.get(snippet);
Log.i("jSalonData",jSalonData.toString());
City = jSalonData.optString("City");
SaloonDetails = SaloonDetails + City;
Zipcode = jSalonData.optString("Zipcode");
SaloonDetails = SaloonDetails +" "+ Zipcode;
HouseNumber = jSalonData.optString("HouseNumber");
SaloonDetails = SaloonDetails +" "+ HouseNumber;
Street = jSalonData.optString("Street");
SaloonDetails = SaloonDetails +" "+ Street;
Log.i("SaloonDetails", SaloonDetails);
addressView.setText(SaloonDetails);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
});
}
按钮的onclick功能是
Button button = ((Button)
selectedLayout.findViewById(R.id.selec_button_id));
button.setOnClickListener(new View.OnClickListener() {
@Override
// On click function
public void onClick(View view) {
Bundle extras = new Bundle();
Button b = (Button)view;
String buttonText = b.getText().toString();
Log.i("buttonText",buttonText);
//String Slecteditem = hm.get(buttonText);
//Log.i("objectidddddd",Slecteditem);
Intent intent = new Intent(view.getContext(),
Salon_Detail.class);
//extras.putString("Slecteditem", Slecteditem);
startActivity(intent);
}
});
【问题讨论】:
标签: javascript android