Android Studio59 [Android Studio] json 데이터 한 눈에 쉽게 알아보는 방법 이런 json 데이터가 있을 때 전부 복사 한 후에 https://jsoneditoronline.org/#left=local.mafaji&right=local.viwoye 위 사이트 접속 후 복사한 데이터를 붙여넣기 후 Copy의 > 표시 클릭하면 한 눈에 알아볼 수 있게 정리되서 보여준다. 2023. 12. 28. [Android Studio] RecyclerView Adapter에서 AlertDialog 처리 private void ShowAlertDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setCancelable(false); builder.setTitle("주소록 삭제"); builder.setMessage("정말 삭제하시겠습니까?"); builder.setNegativeButton("No", null); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 몇번째 데이터를 선택했는지 알아야 한다. in.. 2023. 12. 28. [Android Studio] 다른 액티비티로 데이터 전달 시 클래스의 객체를 전달하는 방법 public class Contact implements Serializable { public String name; public String phone; public String address; public Contact(String name, String phone, String address) { this.name = name; this.phone = phone; this.address = address; } } 먼저, 전달 할 클래스로 가서 Serializable을 구현(implements)한다. 보낼 때 Intent intent = new Intent(); Contact contact = new Contact(name, phone, address); intent.putExtra("contact.. 2023. 12. 28. [Android Studio] RecyclerView에서 몇 번째 행을 눌렀는지 알 수 있는 어뎁터 함수 getAdapterPosition() 상황) RecyclerView의 cardView를 클릭했을 때, 목록 중 몇번째를 클릭했는지 알고 싶을 때 코드 cardView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, UpdateActivity.class); int index = getAdapterPosition(); Contact contact = contactArrayList.get(index); intent.putExtra("index", index); intent.putExtra("contact", contact); ((MainActivity) context).lau.. 2023. 12. 28. [Android Studio] RecyclerView Adapter에서 새로운 액티비티를 실행하는 방법 RecyclerView Adapter에서 ViewHolder에 카드뷰를 클릭했을때의 이벤트를 입력하려고 한다. 새로운 액티비티를 열기 위해서는 새로운 액티비티를 실행할 액티비티가 필요한데 어댑터는 액티비티가 아니다. MainActivity // 어뎁터 만들고 화면에 적용 adapter = new ContactAdapter(MainActivity.this, contactArrayList); recyclerView.setAdapter(adapter); 메인액티비티에서 어뎁터 만들고 화면에 적용하는 부분에서 첫번째 인자에 MainActivity.this를 넣었는데 ContactAdapter Context context; ArrayList contactArrayList; public ContactAdapter(.. 2023. 12. 28. [Android Studio] RecyclerView와 Adapter를 이용해 리스트를 화면에 표시하는 방법 RecyclerView는 여러개의 데이터를 목록으로 처리할때 사용한다. 우선 하나의 행에 대한 화면개발을 먼저 한다. (파일명 contact_row, LinearLayout로 파일 생성) 화면을 구성한다. adapter 패키지를 만들고 안에 클래스를 만든다. 만든 클래스(ContactAdapter) 전체 코드 package com.dongsu.contacts.adapter; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.view.LayoutInflater; import android.view.View; import android.view.Vi.. 2023. 12. 28. [Android Studio] 메뉴 아이콘을 벡터 이미지로 만드는 방법 res 폴더 -> New -> Vector Asset 클릭 Clip art 클릭하면 android studio에서 제공하는 아이콘을 사용할 수 있다. 저장하면 drawble 폴더 안에 저장된다. 2023. 12. 27. [Android Studio] SharedPreferences Shared Preferences는 앱내에서 간단하게 데이터를 저장할때 사용하는 저장소이다. 웹의 localStorage 같은 개념인거 같다. public class MainActivity extends AppCompatActivity { EditText editSentence; Button btnSave; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editSentence = findViewById(R.id.editSentence); btnSave = findViewById(R.id.btnSave); .. 2023. 12. 27. [Android Studio] Activity 단방향 데이터, 양방향 데이터 전달하는 법 단방향 데이터 전달 보낼 때 Intent intent = new Intent(MainActivity.this, SecondActivity.class); intent.putExtra("name", name); intent.putExtra("age", age); startActivity(intent); 인텐트 객체를 만들고 전달 데이터를 key와 value로 세팅해서 보낸다. 받을 때 String name = getIntent().getStringExtra("name"); // 받아온 데이터가 없을 경우 디폴트를 0으로 설정함 int age = getIntent().getIntExtra("age", 0); 보낼 때는 타입과 상관없이 putExtra인 반면, 받을 때는 get 다음에 타입을 맞게 해야된다. g.. 2023. 12. 26. [Android Studio] Activity 간 화면 전환하는 방법 1. 새로운 액티비티 파일을 만든다. (동일한 Empty Views Activity) 2. 인텐트 객체를 생성한다. Intent intent = new Intent(MainActivity.this, SecondActivity.class); startActivity(intent); 인텐트란? 어떤 액티비티가 어떤 액티비티를 실행하겠다는 것 첫번째 인자에는 실행할 액티비티(누가), 두번째 인자에는 실행 당할 액티비티(누구를)가 들어간다. startActivity(변수명)로 실행한다. 2023. 12. 26. 이전 1 2 3 4 5 6 다음