I have a settings activity in android studio where a user will enter a name in a text box. They will click save and go to another activity and their name will show in a textview. I'm having trouble trying to get the name to show in the textview, I've tried a few different things and have gotten a few different errors, it's probably something simple I'm not getting or overlooking. Here is my error+code
public class ActivityDuel extends AppCompatActivity {
public static String getPrefs(String n, Context context) {
final TextView txtD1 = (TextView) getView().findViewById(R.id.txtD1);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
return preferences.getString(n, "name");
txtD1.setText(n);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_duel);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
}
My error is :
error: non-static method <T>findViewById(int) cannot be referenced from a static context
where T is a type-variable:
T extends View declared in method <T>findViewById(int)