Inicio
Buscar
Ingresar
Registrarse
Starfield: el juego que revolucionará el espacio y la tecnología
Hack x Crack - Comunidad de Seguridad informática
»
Programación
»
Java y Android
»
aplicacion listview con imagen no se inicia ni lanza error
Imprimir
Páginas: [
1
]
Ir Abajo
Autor
Tema: aplicacion listview con imagen no se inicia ni lanza error (Leído 4790 veces)
$francisco
{ L6 } Flooder del foro
Mensajes: 781
aplicacion listview con imagen no se inicia ni lanza error
«
en:
Abril 12, 2017, 10:19:01 pm »
muy buenas ire al grano.
MainActivity.java
Código: Java
package
com.example.franciskiko.applicationlistview
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.widget.AdapterView
;
import
android.widget.ListAdapter
;
import
android.widget.ListView
;
import
android.widget.AdapterView.OnItemClickListener
;
import
android.view.View
;
import
android.widget.Toast
;
class
listenItemClick
implements
OnItemClickListener
{
@Override
public
void
onItemClick
(
AdapterView
<?>
parent,
View
view,
int
position,
long
id
)
{
ListAdapter lv
=
(
ListAdapter
)
parent.
getAdapter
(
)
;
String
text
=
(
String
)
lv.
getItem
(
position
)
;
Toast.
makeText
(
view.
getContext
(
)
,text,Toast.
LENGTH_SHORT
)
.
show
(
)
;
}
}
public
class
MainActivity
extends
AppCompatActivity
{
@Override
protected
void
onCreate
(
Bundle savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
)
;
setContentView
(
R.
layout
.
simplelayout
)
;
Weather weather
[
]
=
new
Weather
[
]
{
new
Weather
(
R.
drawable
.
soleado
,
"soleado"
)
,
new
Weather
(
R.
drawable
.
wx_66
,
"nuboso"
)
}
;
WeatherAdapter adapter
=
new
WeatherAdapter
(
getApplicationContext
(
)
,R.
layout
.
listview_item_row
,weather
)
;
View
header
=
(
View
)
getLayoutInflater
(
)
.
inflate
(
R.
layout
.
listview_header
,
null
)
;
ListView
listview
=
(
ListView
)
findViewById
(
R.
id
.
listview_1
)
;
listview.
setOnItemClickListener
(
new
listenItemClick
(
)
)
;
listview.
addHeaderView
(
header
)
;
listview.
setAdapter
(
adapter
)
;
}
Weather.java
Código: Java
package
com.example.franciskiko.applicationlistview
;
/**
* Created by franciskiko on 12/04/2017.
*/
public
class
Weather
{
int
icon
;
String
title
;
public
Weather
(
int
icon,
String
title
)
{
this
.
icon
=
icon
;
this
.
title
=
title
;
}
}
WeatherAdapter.java
Código: Java
package
com.example.franciskiko.applicationlistview
;
import
android.content.Context
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ArrayAdapter
;
public
class
WeatherAdapter
extends
ArrayAdapter
<
Weather
>
{
Context
context
;
int
resource
;
Weather data
[
]
=
null
;
public
WeatherAdapter
(
Context
context,
int
resource, Weather
[
]
data
)
{
super
(
context, resource, data
)
;
this
.
context
=
context
;
this
.
resource
=
resource
;
this
.
data
=
data
;
}
@Override
public
View
getView
(
int
position,
View
convertView, ViewGroup parent
)
{
View
row
=
convertView
;
WeatherHolder holder
=
null
;
if
(
row
==
null
)
{
LayoutInflater inflater
=
LayoutInflater.
from
(
context
)
;
row
=
inflater.
inflate
(
resource,parent
)
;
holder
=
new
WeatherHolder
(
)
;
holder.
img
=
(
ImageView
)
row.
findViewById
(
R.
id
.
imageView
)
;
holder.
title
=
(
TextView
)
row.
findViewById
(
R.
id
.
textView2
)
;
row.
setTag
(
holder
)
;
}
else
{
holder
=
(
WeatherHolder
)
convertView.
getTag
(
)
;
}
Weather weather
=
data
[
position
]
;
holder.
img
.
setImageResource
(
weather.
icon
)
;
holder.
title
.
setText
(
weather.
title
)
;
return
row
;
}
static
class
WeatherHolder
{
ImageView img
;
TextView title
;
}
}
simplelayout.xml
Código: XML
<?xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:orientation
=
"vertical"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
>
<ListView
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
android:id
=
"@+id/listview_1"
/>
</LinearLayout
>
listview_item_row.xml
Código: XML
<?xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
xmlns:app
=
"http://schemas.android.com/apk/res-auto"
android:orientation
=
"vertical"
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
>
<ImageView
android:id
=
"@+id/imageView"
android:layout_width
=
"wrap_content"
android:layout_height
=
"match_parent"
/>
<TextView
android:id
=
"@+id/textView2"
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
/>
</LinearLayout
>
listview_header.xml
Código: XML
<?xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:orientation
=
"horizontal"
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
>
<TextView
android:id
=
"@+id/textView"
android:layout_width
=
"match_parent"
android:layout_height
=
"wrap_content"
android:text
=
"TextView"
/>
</LinearLayout
>
log de android studio
04-12 20:05:53.509 5075-5075/com.ionicframework.ionicproject641096 W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
04-12 20:07:28.010 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:07:28.048 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db.18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:07:28.053 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:08:35.800 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:08:35.831 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db.18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:08:35.849 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:10:09.741 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:10:10.036 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db.18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:10:10.053 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:10:51.207 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:10:51.514 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db.18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
04-12 20:10:51.527 2281-2290/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed
Las imagenes estan en:
./res/drawable/soleado.png
./res/drawable/wx_66.png
Ni idea de porque no funciona pero no logro solucionar el problema.
En línea
Imprimir
Páginas: [
1
]
Ir Arriba
Hack x Crack - Comunidad de Seguridad informática
»
Programación
»
Java y Android
»
aplicacion listview con imagen no se inicia ni lanza error
Va un mudo y le dice a un sordo: Hack x Crack usa cookies. Pues eso...
OK
Learn more