내 목록보기를 설정할 때 목록의 항목을 클릭하면 OverlayItems와 함께 제공되는 지오 포인트에 액세스하기 때문에 목록보기의 어댑터로 OverlayItems의 Arraylist를 설정합니다.목록 제목이 아닌 오버레이 항목의 ID 표시
그러나이 솔루션은 OverlayItems의 다른 제목은 표시하지 않기 때문에 다소보기 흉한 목록보기를 제공하지만 [email protected]
과 같은 것입니다.
누가이 문제를 해결할 수있는 가장 쉬운 방법을 알고 있습니까 (제목을 표시하고 여전히 geopoints에 액세스 할 수 있습니까?) 저는 이것을 사용자 지정 목록보기로해야한다고 생각합니다. 그러나 이것이 확실하지 않습니다. 가장 쉽고/가장 효율적인 방법.
adapter = new ArrayAdapter<OverlayItem>(this, android.R.layout.simple_list_item_1, custom.pinpoints);
listView.setAdapter(adapter);
==>
전체 코드 :
public class Main extends MapActivity implements OnTabChangeListener{
/** Called when the activity is first created. */
private static final String LIST_TAB_TAG = "List";
private static final String MAP_TAB_TAG = "Map";
MapView map;
ListView listView;
TabHost tabHost;
long start;
long stop;
int x, y;
MyLocationOverlay compass;
MyLocationOverlay MyLoc;
MapController controller;
GeoPoint touchedPoint;
Drawable d;
List<Overlay> overlayList;
CustomPinpoint custom;
static Context context;
ArrayAdapter<OverlayItem> adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
context = getApplicationContext();
listView = (ListView) findViewById(R.id.list);
listView.setEmptyView((TextView) findViewById(R.id.empty));
d = getResources().getDrawable(R.drawable.ic_launcher);
custom = new CustomPinpoint(d,Main.this);
listView.setLongClickable(true);
adapter = new ArrayAdapter<OverlayItem>(this, android.R.layout.simple_list_item_1, custom.pinpoints);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
GeoPoint geoPoint = ((OverlayItem) listView.getAdapter().getItem(position)).getPoint();
if(geoPoint != null) {
map.getController().animateTo(geoPoint);
tabHost.setCurrentTab(1);
}
}
});
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
final AlertDialog alert3 = new AlertDialog.Builder(Main.this).create();
alert3.setTitle("Pick an option.");
alert3.setButton(DialogInterface.BUTTON_POSITIVE,"Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alert3.setButton(DialogInterface.BUTTON_NEUTRAL,"Modify", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
LayoutInflater factory = LayoutInflater.from(context);
View promptsView = factory.inflate(R.layout.prompts, null);
final AlertDialog alert4 = new AlertDialog.Builder(Main.this).create();
alert4.setView(promptsView);
final EditText userInput1 = (EditText) promptsView.findViewById(R.id.editTextInput1);
final EditText userInput2 = (EditText) promptsView.findViewById(R.id.editTextInput2);
userInput1.setInputType(InputType.TYPE_CLASS_TEXT);
userInput1.setCursorVisible(true);
userInput2.setInputType(InputType.TYPE_CLASS_TEXT);
userInput2.setCursorVisible(true);
alert4.setButton (DialogInterface.BUTTON_NEGATIVE,"Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
custom.modifyPinpoint(userInput1.getText().toString(), userInput2.getText().toString(),position);
map.postInvalidate();
}
});
alert4.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert4.show();
}
});
alert3.setButton(DialogInterface.BUTTON_NEGATIVE,"Delete", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
custom.deletePinpoint(position);
adapter.notifyDataSetChanged();
}
});
alert3.show();
return true;
}
});
map = (MapView) findViewById(R.id.mapview);
map.setBuiltInZoomControls(true);
map.postInvalidate();
Touch t = new Touch();
overlayList = map.getOverlays();
overlayList.add(t);
compass = new MyLocationOverlay(Main.this, map);
overlayList.add(compass);
controller = map.getController();
MyLoc = new MyLocationOverlay(Main.this, map);
overlayList.add(MyLoc);
map.postInvalidate();
MyLoc.runOnFirstFix(new Runnable() {
public void run() {
map.getController().animateTo(MyLoc.getMyLocation());
}
});
tabHost.addTab(tabHost.newTabSpec(LIST_TAB_TAG).setIndicator("List").setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return listView;
}
}));
tabHost.addTab(tabHost.newTabSpec(MAP_TAB_TAG).setIndicator("Map").setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return map;
}
}));
tabHost.setCurrentTab(1);
tabHost.setCurrentTab(0);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
compass.disableCompass();
super.onPause();
MyLoc.disableMyLocation();
finish();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
compass.enableCompass();
super.onResume();
MyLoc.enableMyLocation();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
class Touch extends Overlay {
public boolean onTouchEvent(MotionEvent e, MapView m) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
start = e.getEventTime();
x = (int) e.getX();
y = (int) e.getY();
touchedPoint = map.getProjection().fromPixels(x, y);
}
if (e.getAction() == MotionEvent.ACTION_UP) {
stop = e.getEventTime();
}
if (stop - start > 1200) {
final AlertDialog alert = new AlertDialog.Builder(Main.this).create();
alert.setTitle("Pick an option.");
alert.setButton(DialogInterface.BUTTON_POSITIVE,"Place a pinpoint.", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
LayoutInflater factory = LayoutInflater.from(context);
View promptsView = factory.inflate(R.layout.prompts, null);
final AlertDialog alert2 = new AlertDialog.Builder(Main.this).create();
alert2.setView(promptsView);
final EditText userInput1 = (EditText) promptsView.findViewById(R.id.editTextInput1);
final EditText userInput2 = (EditText) promptsView.findViewById(R.id.editTextInput2);
userInput1.setInputType(InputType.TYPE_CLASS_TEXT);
userInput1.setCursorVisible(true);
userInput2.setInputType(InputType.TYPE_CLASS_TEXT);
userInput2.setCursorVisible(true);
alert2.setButton (DialogInterface.BUTTON_NEGATIVE,"Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
OverlayItem overlayItem = new OverlayItem(touchedPoint, userInput1.getText().toString(), userInput2.getText().toString());
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
map.postInvalidate();
}
});
alert2.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert2.show();
}
});
alert.setButton(DialogInterface.BUTTON_NEUTRAL,"Get address.",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
// TODO Auto-generated method stub
Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
try{
List<Address> address = geocoder.getFromLocation(touchedPoint.getLatitudeE6() /1E6, touchedPoint.getLongitudeE6()/1E6, 1);
if (address.size() > 0){
String display = "";
for (int i = 0; i < address.get(0).getMaxAddressLineIndex(); i++){
display += address.get(0).getAddressLine(i) + "\n";
}
Toast t3 = Toast.makeText(getBaseContext(), display, Toast.LENGTH_LONG);
t3.show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
}
}
});
alert.setButton(DialogInterface.BUTTON_NEGATIVE,"Toggle View", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
if (map.isSatellite()){
map.setSatellite(false);
}else{
map.setSatellite(true);
}
}
});
alert.show();
return true;
}
return false;
}
}
public void gpsCurrentLocation()
{
tabHost.setCurrentTab(1);
GeoPoint p = MyLoc.getMyLocation();
if (p == null){
Toast.makeText(Main.this, "Your location wasn't found.", Toast.LENGTH_SHORT).show();
}
else{
map.getController().animateTo(p);
}
}
// Menu XML file (menu.xml)
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.map_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.my_location:
Toast.makeText(Main.this, "Moving To Current location", Toast.LENGTH_SHORT).show();
gpsCurrentLocation();
return true;
case R.id.menu_clear:
custom.clearPinpoint();
adapter.notifyDataSetChanged();
}
return false;
}
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
}
}
더 많은 코드를 게시하십시오. – user370305
완료. 정말로 처음 50 줄 정도만 필요합니다. – user1534543