gpt4 book ai didi

android - 单击 infoWindowAdapter 时如何启动新 Activity ?

转载 作者:行者123 更新时间:2023-11-29 20:59:43 24 4
gpt4 key购买 nike

大家好,我是 Android 的初学者,但我想做的是在我按下 map 中的 infoWindowAdapter 时开始一项新 Activity 。代码看起来很简单,但它不起作用,我不知道为什么。你能帮助我吗?我已经在 list 中声明了我的新 Activity (MoreInfoActivity),我想从主要 Activity 中调用它。您可以在下面找到我所有的“MoreInfoActivity”源、它从 MainActivity 调用以及 list 中的声明。非常感谢

当我按下 InfoWindowAdapter 时从 MainActivity 调用:[UPDATED]

final Activity thiz = this;
map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

@Override
public void onInfoWindowClick(Marker marker) {
/*Nuova chiamata di un activity (scelta perché più pratica e la richiamiamo anche dalla listview)*/
/*************************************************************************************************/

String nome_luogo = marker.getTitle();
Intent piu_info = new Intent(thiz, MoreInfoActivity.class);
piu_info.putExtra("nome", nome_luogo);
startActivity(piu_info);

/*************************************************************************************************/

}
});

MoreInfoActivity:[更新]

    public class MoreInfoActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_moreinfo);

Bundle extras = getIntent().getExtras();
if (extras != null){
String value = extras.getString("nome");
prendi_informazioni(value);
}
}

public void prendi_informazioni(String nome_luogo){
View layout = getWindow().getDecorView().findViewById(R.id.immagine_luogo);
//String nome_luogo = marker.getTitle();

BuildInfoMatrix printinfo = new BuildInfoMatrix();
printinfo.Fill_Matrix();
printinfo.Read_Matrix(nome_luogo, layout);
}
}

list :

<!-- More informations Activity -->
<activity
android:name="com.example.findmyclients.MoreInfoActivity"
android:screenOrientation="portrait">
</activity>

日志: http://pastebin.com/pKuW4LCk

最佳答案

我不能完全确定您的语法是否正确。我质疑的部分是 MainActivity.this。我不完全确定那是什么意思,但它可能是该类的一个实例。相反,在您的 clickListener 之外创建一个 Activity 变量并从您的 clickListener 引用。示例:

final Activity thiz = this; /* Needs to be final so you can reference it in inner class */

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

@Override
public void onInfoWindowClick(Marker marker) {
View v2 = getLayoutInflater().inflate(R.layout.activity_moreinfo, null);
MoreInfoActivity prova = new MoreInfoActivity();
prova.prendi_informazioni(marker);

Intent piu_info = new Intent(thiz, MoreInfoActivity.class);
startActivity(piu_info);
}

});

作为旁注,您永远不应该自己实例化 Activity 的实例。如果您需要向 Activity 传递额外的参数,请通过添加额外的方式将其附加到 Intent 。看这里: http://developer.android.com/reference/android/content/Intent.html#putExtra(java.lang.String , 双 [])

例如:

  String nome_luogo = marker.getTitle();
piu_info.putExtra("marker", nome_luogo );

并在 MoreInfoActivity 的 onCreate 中:

    String marker = getIntent().getExtras().getString("marker");
doSomething(marker);

你现在这样做的方式,即使你没有得到空指针异常,你的参数也不会被MoreInfoActivity看到

关于android - 单击 infoWindowAdapter 时如何启动新 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26488491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com