Hack x Crack - Comunidad de Seguridad informática

Programación => Java y Android => Mensaje iniciado por: $francisco en Abril 12, 2017, 10:19:01 pm

Título: aplicacion listview con imagen no se inicia ni lanza error
Publicado por: $francisco en Abril 12, 2017, 10:19:01 pm
muy buenas ire al grano.

MainActivity.java

Código: Java
  1. package com.example.franciskiko.applicationlistview;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.widget.AdapterView;
  6. import android.widget.ListAdapter;
  7. import android.widget.ListView;
  8. import android.widget.AdapterView.OnItemClickListener;
  9. import android.view.View;
  10. import android.widget.Toast;
  11.  
  12. class listenItemClick implements OnItemClickListener {
  13.  
  14.   @Override
  15.   public void onItemClick(AdapterView<?> parent, View view,int position, long id){
  16.     ListAdapter lv = (ListAdapter) parent.getAdapter();
  17.     String text = (String) lv.getItem(position);
  18.     Toast.makeText(view.getContext(),text,Toast.LENGTH_SHORT).show();
  19.   }
  20.  
  21. }
  22.  
  23. public class MainActivity extends AppCompatActivity {
  24.  
  25.   @Override
  26.   protected void onCreate(Bundle savedInstanceState) {
  27.     super.onCreate(savedInstanceState);
  28.     setContentView(R.layout.simplelayout);
  29.  
  30.     Weather weather[] = new Weather[]{
  31.       new Weather(R.drawable.soleado,"soleado"),
  32.       new Weather(R.drawable.wx_66,"nuboso")
  33.     };
  34.  
  35.     WeatherAdapter adapter = new WeatherAdapter(getApplicationContext(),R.layout.listview_item_row,weather);
  36.     View header = (View)getLayoutInflater().inflate(R.layout.listview_header,null);
  37.  
  38.     ListView listview = (ListView) findViewById(R.id.listview_1);
  39.     listview.setOnItemClickListener(new listenItemClick());
  40.     listview.addHeaderView(header);
  41.     listview.setAdapter(adapter);
  42.   }

Weather.java

Código: Java
  1. package com.example.franciskiko.applicationlistview;
  2.  
  3. /**
  4.  * Created by franciskiko on 12/04/2017.
  5.  */
  6.  
  7. public class Weather {
  8.   int icon;
  9.   String title;
  10.  
  11.   public Weather(int icon, String title){
  12.     this.icon = icon;
  13.     this.title = title;
  14.   }
  15.  
  16. }

WeatherAdapter.java

Código: Java
  1. package com.example.franciskiko.applicationlistview;
  2.  
  3. import android.content.Context;
  4. import android.widget.ImageView;
  5. import android.widget.TextView;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.ArrayAdapter;
  10.  
  11.  
  12. public class WeatherAdapter extends ArrayAdapter<Weather> {
  13.   Context context;
  14.   int resource;
  15.   Weather data[] = null;
  16.   public WeatherAdapter(Context context, int resource, Weather[] data) {
  17.     super(context, resource, data);
  18.     this.context = context;
  19.     this.resource = resource;
  20.     this.data = data;
  21.   }
  22.  
  23.   @Override
  24.   public View getView(int position, View convertView, ViewGroup parent){
  25.     View row = convertView;
  26.     WeatherHolder holder = null;
  27.     if(row == null){
  28.       LayoutInflater inflater = LayoutInflater.from(context);
  29.       row = inflater.inflate(resource,parent);
  30.       holder = new WeatherHolder();
  31.       holder.img = (ImageView) row.findViewById(R.id.imageView);
  32.       holder.title = (TextView) row.findViewById(R.id.textView2);
  33.       row.setTag(holder);
  34.     }
  35.     else{
  36.       holder = (WeatherHolder) convertView.getTag();
  37.     }
  38.  
  39.     Weather weather = data[position];
  40.     holder.img.setImageResource(weather.icon);
  41.     holder.title.setText(weather.title);
  42.  
  43.     return row;
  44.   }
  45.  
  46.   static class WeatherHolder{
  47.     ImageView img;
  48.     TextView title;
  49.   }
  50. }

simplelayout.xml
Código: XML
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical" android:layout_width="fill_parent"
  4.    android:layout_height="fill_parent"
  5.  >
  6.   <ListView
  7.    android:layout_width="fill_parent"
  8.    android:layout_height="fill_parent"
  9.    android:id="@+id/listview_1"/>
  10. </LinearLayout>

listview_item_row.xml

Código: XML
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.  xmlns:app="http://schemas.android.com/apk/res-auto"
  4.  android:orientation="vertical" android:layout_width="match_parent"
  5.    android:layout_height="match_parent">
  6.  
  7.   <ImageView
  8.    android:id="@+id/imageView"
  9.    android:layout_width="wrap_content"
  10.    android:layout_height="match_parent"
  11.     />
  12.  
  13.   <TextView
  14.    android:id="@+id/textView2"
  15.    android:layout_width="match_parent"
  16.    android:layout_height="match_parent"
  17.     />
  18. </LinearLayout>

listview_header.xml

Código: XML
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="horizontal" android:layout_width="match_parent"
  4.    android:layout_height="match_parent">
  5.  
  6.   <TextView
  7.    android:id="@+id/textView"
  8.    android:layout_width="match_parent"
  9.    android:layout_height="wrap_content"
  10.    android:text="TextView" />
  11. </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.