当我尝试实现下面这段代码时,它会给出下面的错误。我不明白的是EditText
输入字段的静态内容如何?这可能是非常基本的,我可能会在这里失踪。这是如何编辑文本字段静态内容?
Error:(28, 32) error: non-static method findViewById(int) cannot be referenced from a static context
代码:
package com.example.kheriaa.meme_fragments_v1;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
public class TopSectionFragment extends Fragment {
private EditText TopText;
private EditText BottomText ;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frags_layout, container, false);
TopText = (EditText) View.findViewById(R.id.TopText);
//return super.onCreateView(inflater, container, savedInstanceState);
return v;
}
}
这是因为我认为目标是 “V”?而不是查看? – supersayan
@supersayan是因为View的实例是v,所以你应该使用v.findViewById(R.id.TopText); –
@supersayan我补充说明 – rafsanahmad007