[Android/Layout]ListView Click Event : 팝업창 생성

2021. 2. 7. 15:20Android/UI-UX 디자인

728x90
반응형

<구현 화면>

팝업창 구현 화면

1. 팝업창 activity를 생성해준다. (PopupActivity.java, activity_popup.xml)

public class PopupActivity extends Activity {

    TextView txtText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup);

        //UI 객체생성
        txtText = (TextView)findViewById(R.id.txtPopup);

        //데이터 가져오기
        Intent intent = getIntent();
        String data = intent.getStringExtra("data");
        txtText.setText(data);
    }
}

* extends AppCompatActivity를 extends Activity로 변경!!

   AndroidManifest.java 수정 시 충동 생김

 

2. AndroidManifest.java에서 PopupActivity을 Dialog로 변경 (팝업화면)

<activity android:name=".PopupActivity" android:theme="@android:style/Theme.Dialog"></activity>

 

3. DogMainActivity.java에서 리스트뷰 내 아이템 선택 시 팝업화면 호출

ListView listview = (ListView) findViewById(R.id.listView);

listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
  @Override
  public void onItemClick(AdapterView parent, View v, int position, long id){
    String value = "TestPopup \n TestPopup \n TestPopup \n TestPopup "
    	+ "\n TestPopup \n TestPopup \n TestPopup \n TestPopup "
    	+ "\n TestPopup \n TestPopup \n TestPopup \n TestPopup"	// 테스트 문구;
    Log.d(TAG, "선택했어요.");
    Intent intent = new Intent(DogMainActivity.this, PopupActivity.class);
    intent.putExtra("data", value);
    startActivityForResult(intent, 1);
  }
});
728x90
반응형