java - 点击打开最初隐藏的 ListView

标签 java android android-intent listener google-maps-api-2

我有一张 map ,在android studio上使用谷歌地图api2,当我点击任何地方时,我想打开一个 ListView ,其中会有单选按钮和其他类型的东西。我不知道该怎么做,如何使用 Intent ,如何使用听众,任何人都可以帮助我吗?这是我到目前为止得到的代码:

public class MainActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener {

private MapView mapV;
private GoogleMap map;
private GoogleMapOptions options;
private CameraUpdate camUp;
private double lat,lon;
private LatLng koordinate;
private String provider;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    map = fm.getMap();
    map.setMyLocationEnabled(true);
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(provider);
    koordinate = new LatLng(location.getLatitude(),location.getLongitude());
    if(location!=null){
        onLocationChanged(location);


    }
    locationManager.requestLocationUpdates(provider, 20000, 0, this);
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(koordinate, 10);
    map.animateCamera(cameraUpdate);
}



public void openList(View view)
{
    Intent intent = new Intent(intent.ACTION_VIEW ,);
    ListView list = (ListView) findViewById(R.id.idList);

}

XML 文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >



<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"/>

<ExpandableListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/idList"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:onClick="openList"/>

最佳答案

Intent 类通常与按钮相关联。 单击按钮时,Intent 类可用于简单地唤醒/启动另一个 Activity ,或者它可以将一些数据(字符串/整数/等)传递给该 Activity ,如果需要,它还可以获取一些数据。

要简单地唤醒另一个 Activity ,您可以:

Intent i = new Intent (*activity_action_name*);
startActivity(i);

对于监听器来说,最好在 onClick 次数较多时使用。因为这是减少数据冗余的好方法。如果你只有一个 onClick.没有必要使用OnClickListener。

示例:如果您有两个按钮。您可以执行以下操作。

//in onCreate declare some buttons
Button bt1 = (Button) findViewById(R.id.*button1_id*);
bt1.setOnClickListener(new clsOnClickListener());
Button bt2 = (Button) findViewById(R.id.*button2_id*);
bt2.setOnClickListener(new clsOnClickListener());

//You can create a class that implements OnClickListener
private class clsOnClickListener implements View.OnClickListener{
public void onClick(View v){
     if (v.getId()==R.id.button1_id{
          //do what you want
     }
     else if (v.getId()==R.id.button2_id){
         //do something else
     }
 }
}

关于java - 点击打开最初隐藏的 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28618068/

相关文章:

android - 如何访问内部存储的图像

java - 在 Windows 上使用 Redis-cli 在 Redis 中加载 CSV 文件

android - 应用程序死于 "Low Memory: No more background processes."

java - 如何使用最佳方式检索 Json 文件

Android,侧载应用程序并通过 Google Play 保持最新状态

android - android如何知道wifi连接是否可以上网

java - 如何从我的 Android 应用程序中删除或编辑 G-calendar 中的事件?

java - 是否可以使用 Web 服务器 api 中的 MpAndroid 显示图表?

java - 无法实例化 HttpConnection 类型

Java 图形用户界面 |有序列表