작성
·
318
0
아래는 코드들입니다.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="@+id/mainlistview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
MainActivity.kt
package com.example.listview
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ListView
import android.widget.Toast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//val list_item = mutableListOf<String>()
//list_item.add("A")
//list_item.add("B")
//list_item.add("C")
val list_item2 = mutableListOf<listviewmodel>()
list_item2.add(listviewmodel("a","b"))
list_item2.add(listviewmodel("c","d"))
//어뎁터와 메인을 연결하는 과정
val listview = findViewById<ListView>(R.id.mainlistview)
val listviewadapter = ListViewAdapter(list_item2)
listview.adapter = listviewadapter
listview.setOnItemClickListener{parent, view, position, id ->
Toast.makeText(this, list_item2[position].text1,Toast.LENGTH_LONG).show()
}
}
}
ListViewAdapter.kt
package com.example.listview
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
class ListViewAdapter(val List : MutableList<listviewmodel>) : BaseAdapter() {
override fun getCount(): Int {
return List.size
}
override fun getItem(p0: Int): Any {
return List[p0]
}
override fun getItemId(p0: Int): Long {
return p0.toLong()
}
override fun getView(position: Int, converView: View?, parent: ViewGroup?): View {
var converView = converView
if (converView == null) {
converView = LayoutInflater.from(parent?.context).inflate(R.layout.listview_item, parent, false)
}
val title = converView!!.findViewById<TextView>(R.id.listviewitemview1)
val title2 = converView!!.findViewById<TextView>(R.id.listviewitemview2)
title.text = List[position].text1
title2.text = List[position].text2
return converView!!
}
}
llistview_item.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="@+id/mainlistview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
이렇게 코드를 적고 디버깅을 할 때
07/18 14:45:35: Launching 'app' on leejanghan.
Installation did not succeed.
The application could not be installed.
List of apks:
[0] 'C:\Users\User\AndroidStudioProjects\listview\app\build\intermediates\apk\debug\app-debug.apk'
Installation failed due to: ''cmd package install-create -r -t --user current --full --dont-kill --skip-verification -S 5146924' returns error 'Unknown failure: Exception occurred while executing 'install-create':
android.os.ParcelableException: java.io.IOException: Requested internal only, but not enough space
at android.util.ExceptionUtils.wrap(ExceptionUtils.java:34)
at com.android.server.pm.PackageInstallerService.createSession(PackageInstallerService.java:595)
at com.android.server.pm.PackageManagerShellCommand.doCreateSession(PackageManagerShellCommand.java:3416)
at com.android.server.pm.PackageManagerShellCommand.runInstallCreate(PackageManagerShellCommand.java:1561)
at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:232)
at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
at android.os.ShellCommand.exec(ShellCommand.java:38)
at com.android.server.pm.PackageManagerService$IPackageManagerImpl.onShellCommand(PackageManagerService.java:5952)
at android.os.Binder.shellCommand(Binder.java:1049)
at android.os.Binder.onTransact(Binder.java:877)
at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:4313)
at com.android.server.pm.PackageManagerService$IPackageManagerImpl.onTransact(PackageManagerService.java:5936)
at android.os.Binder.execTransactInternal(Binder.java:1285)
at android.os.Binder.execTransact(Binder.java:1244)
Caused by: java.io.IOException: Requested internal only, but not enough space
at com.android.internal.content.InstallLocationUtils.resolveInstallVolume(InstallLocationUtils.java:241)
at com.android.internal.content.InstallLocationUtils.resolveInstallVolume(InstallLocationUtils.java:152)
at com.android.internal.content.InstallLocationUtils.resolveInstallVolume(InstallLocationUtils.java:167)
at com.android.server.pm.PackageInstallerService.createSessionInternal(PackageInstallerService.java:803)
at com.android.server.pm.PackageInstallerService.createSession(PackageInstallerService.java:592)
... 12 more''
Retry
Failed to launch an application on all devices
와 같은 오류가 뜹니다
코드의 내용은 잘 적은 것 같은데, 오류가 발생해 그 이유가 무엇인지 궁금합니다.
감사합니다!!