사용자 정의 기본 설정 <com.myproject.CustomPreference android:layout="@layout/preferences_main" />
을 작성하여 사용자 이름, 전화 번호 및 프로필 그림 (아직 중요하지 않은 원 안에 있음)을 표시하고자합니다. Preference를 확장 한 CustomPreference.class를 사용하여 기본 설정에서 사용자 이름과 전화 번호를 얻을 수 있었지만 getExternalFilesDir
은이 클래스에 대해 정의되지 않았기 때문에 프로필 사진에 대한 경로를 얻지 못합니다.getExternalFilesDir이 사용자 정의 기본 설정에서 정의되지 않았습니다.
public class CustomPreference extends Preference {
private TextView tvusername, tvphonenumber;
private ImageView profilepic_profile;
public CustomPreference(Context context, AttributeSet attrs) {
super(context, attrs);
this.setWidgetLayoutResource(R.layout.preferences_main);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
tvusername = (TextView) view.findViewById(R.id.tvusername);
tvphonenumber = (TextView) view.findViewById(R.id.tvphonenumber);
profilepic_profile = (ImageView) view
.findViewById(R.id.profilepic_profile);
final SharedPreferences prefs = getSharedPreferences();
// entering preference username in text view
String username = prefs.getString("username", null);
tvusername.setText(username);
// entering preference phonenumber in text view
String phonenumber = prefs.getString("phonenumber", null);
tvphonenumber.setText(phonenumber);
// Show currently saved profile pic in imageview
String fname = "profile.png";
Bitmap photo2 = BitmapFactory.decodeFile(getExternalFilesDir(null)
.getAbsolutePath() + "/images/" + fname);
if (photo2 != null) {
GraphicsUtil graphicUtil2 = new GraphicsUtil();
profilepic_profile.setImageBitmap(graphicUtil2.getCircleBitmap(
photo2, 16));
} else {
// profilepic_profile.setBackground(profile_pic_big);
}
}
}
너무 쉽고 시간이 많이 걸리지는 않았습니다. 덕분에 많은 성공을 거두었습니다. – sascha
@Apoorv 가능 편집. 컨텍스트를 저장하지 마십시오. 아마 뭔가가 연결되어 있기 때문에 os가 정리 작업을 수행 할 때 문제가 발생할 수 있습니다. 대신 getExternalFilesDir()에서 결과를 저장하십시오. – danny117