Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更改片段中的文本字段_Android_Google Maps_Android Fragments - Fatal编程技术网

Android 更改片段中的文本字段

Android 更改片段中的文本字段,android,google-maps,android-fragments,Android,Google Maps,Android Fragments,我正在开发一个地图应用程序。一个活动有两个片段,其中一个是映射,另一个是在markerclick()上创建的。片段中有文本字段,我需要在单击标记以获取特定标记位置和信息后对其进行更改。我的标记类: public static BlankFragment newInstance(String param1, String param2,String param3,String param4,double param5,double param6) { BlankFragment fragm

我正在开发一个地图应用程序。一个活动有两个片段,其中一个是映射,另一个是在markerclick()上创建的。
片段中有文本字段,我需要在单击标记以获取特定标记位置和信息后对其进行更改。我的标记类:

public static BlankFragment newInstance(String param1, String param2,String param3,String param4,double param5,double param6) {
    BlankFragment fragment = new BlankFragment();
    Bundle args = new Bundle();
    args.putString("addressLine", param1);
    args.putString("countryName", param2);
    args.putString("imageURL", param3);
    args.putString("comment", param4);
    args.putDouble("lat", param5);
    args.putDouble("lng", param6);
    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        addressFromIntent=getArguments().getString("addressLine");
        countryFromIntent=getArguments().getString("countryName");
        commentFromIntent=getArguments().getString("comment");
        photoPath=getArguments().getString("imageURL");
        latFromIntent=getArguments().getDouble("lat", 0);
        lngFromIntent=getArguments().getDouble("lng", 0);
        addressView=(TextView)getActivity().findViewById(R.id.textView);
        countryView=(TextView)getActivity().findViewById(R.id.textView2);
        latlngView=(TextView)getActivity().findViewById(R.id.textView3);
        saveButton=(Button)getView().findViewById(R.id.button);
        saveButton.setText("Save");
        imageView=(ImageView)getActivity().findViewById(R.id.imageView);
        commentView=(EditText)getActivity().findViewById(R.id.editText);

        final String latlngTextField=String.valueOf(latFromIntent)+", "+String.valueOf(lngFromIntent);
        latlngView.setText(latlngTextField);
        if (photoPath.equals("")) {
            imageView.setImageResource(R.drawable.image);
        } else {
            imageView.setImageURI(Uri.parse(photoPath));
        }
        commentView.setText(commentFromIntent);
        commentView.setHint("Enter comment here...");
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dispatchTakePictureIntent();
                Toast.makeText(getActivity().getApplicationContext(), photoPath, Toast.LENGTH_SHORT).show();
            }
        });
        commentView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                commentModified++;

            }
        });
    }
}
我的主要活动
onMarkerClick()
方法:

@Override
public boolean onMarkerClick(Marker marker) {
    CustomMarker customMarker = list.get(new LatLng(marker.getPosition().latitude,marker.getPosition().longitude));
    getFragmentManager()
        .beginTransaction()
        .replace(R.id.map, BlankFragment.newInstance(customMarker.getAddressLine(),customMarker.getCountryName(),customMarker.getImageURL(),customMarker.getComment(), marker.getPosition().latitude,marker.getPosition().longitude))
        .addToBackStack(null) // enables back key
        .setTransition(FragmentTransaction.TRANSIT_ENTER_MASK) // if you need transition
        .commit();
我在尝试设置按钮文本(以及其他字段)时得到一个空指针。我怎样才能解决这个问题


编辑:行
saveButton=(Button)getView().findViewById(R.id.Button)也不能与
getActivity()
一起使用。

使用膨胀视图查找视图<代码>视图.findViewById()
onCreateView
方法中调用此函数,您能澄清一下吗?我还不太擅长这个
addressView=(TextView)view.findviewbyd(R.id.TextView)在片段中的
onCreateView
方法中调用它们。
saveButton.setText(“save”)
会导致相同的空指针,即使我将它们移动到
onCreateView()
。只要选中它们,如果我没有设置它们,就会创建文本视图。所以我知道,将它们移动到
onCreateView
也同样有效,但设置现在不起作用