gpt4 book ai didi

java - Android LayoutInflater 获取 EditText 数据

转载 作者:行者123 更新时间:2023-11-29 21:04:42 26 4
gpt4 key购买 nike

这是我的 GoogleMapAPI,我希望用户可以先输入标记信息,然后使用它来制作标记。

但是 LogCat 总是说“String MarkerInfo = markerInfo.getText().toString();”失败。

抱歉,我是编码新手。请帮助我。

public void onMapLongClick(final LatLng point) {

AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
builder1.setTitle(R.string.funtion);
builder1.setItems(choice, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int selectedItem) {
Toast.makeText(MainActivity.this,"You Select Letter "+choice[selectedItem],Toast.LENGTH_SHORT).show();
dialog.dismiss();
if(selectedItem==1){
AlertDialog.Builder builder2;
Context mContext = MainActivity.this;
LayoutInflater inflater = getLayoutInflater();
builder2 = new AlertDialog.Builder(mContext);
markerInfo = (EditText)findViewById(R.id.markerInfo);
builder2.setView(inflater.inflate(R.layout.markerinfo, null))
.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface marker, int id) {
String MarkerInfo = markerInfo.getText().toString();
map.addMarker(new MarkerOptions()
.position(point)
.title(MarkerInfo)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface marker, int id) {
}
});
builder2.setTitle(R.string.typeinfo);
AlertDialog marker = builder2.create();
marker.show();
}
}
});
AlertDialog alert = builder1.create();
alert.show();
}

最佳答案

看起来 R.id.markerInfo 是在 markerinfo.xml 中声明的,因此您必须使用 markerinfo.xml 的“膨胀”版本来检索 编辑文本

View view = inflater.inflate(R.layout.markerinfo, null);
markerInfo = (EditText)view.findViewById(R.id.markerInfo);
builder2.setView(view);

关于java - Android LayoutInflater 获取 EditText 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24943725/

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