Programación y Desarrollo para Android Subforo exclusivo para temas de programación de software para PDAs y desarrollo de aplicaciones, interfaces, etc bajo Android


 
Herramientas
  #1  
Viejo 02/07/13, 12:25:02
Avatar de wolfcat90
wolfcat90 wolfcat90 no está en línea
Desarrollador
Mensajes: 445
 
Fecha de registro: jun 2012
Mensajes: 445
Modelo de smartphone: Samsung Galaxy Trend Plus
Versión de ROM: Stock
Tu operador: Movistar
Mencionado: 4 comentarios
Tagged: 1 hilos
Ayuda con Launcher App

Hola! soy nuevo en este foro y necesito vuestra ayuda. He estado desarrollando una aplicacion tipo Launcher, y he empezado por crear un GridView y mostrar ahi todas las apps. Mi problema es que en vez de un GridView aparece un ListView. Alguien puede ayudarme? este es mi codigo:

MainActivity.java

Código:
public class MainActivity extends Activity {
    private GridView mGrid;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // set layout for the main screen
        setContentView(R.layout.layout_main);        
        // load list application
        mGrid = (GridView)findViewById(R.id.lvApps);
        // create new adapter
        AppInfoAdapter adapter = new AppInfoAdapter(this, Utilities.getInstalledApplication(this), getPackageManager());
        // set adapter to list view
        mGrid.setAdapter(adapter);
        // implement event when an item on list view is selected
        mGrid.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
        // get the list adapter
        AppInfoAdapter appInfoAdapter = (AppInfoAdapter)parent.getAdapter();
        // get selected item on the list
        ApplicationInfo appInfo = (ApplicationInfo)appInfoAdapter.getItem(pos);
        // launch the selected application
        Utilities.launchApp(parent.getContext(), getPackageManager(), appInfo.packageName);
        }
});
    }
}
AppInfo.java

Código:
public class AppInfoAdapter extends BaseAdapter {

private Context mContext;

private List<ApplicationInfo> mListAppInfo;

private PackageManager mPackManager;



public AppInfoAdapter(Context c, List<ApplicationInfo> list, PackageManager pm) {

mContext = c;

mListAppInfo = list;

mPackManager = pm;

}



@Override

public int getCount() {

return mListAppInfo.size();

}



@Override

public Object getItem(int position) {

return mListAppInfo.get(position);

}



@Override

public long getItemId(int position) {

return position;

}



@Override

public View getView(int position, View convertView, ViewGroup parent) {

// get the selected entry

ApplicationInfo entry = mListAppInfo.get(position);



// reference to convertView

View v = convertView;



// inflate new layout if null

if(v == null) {

LayoutInflater inflater = LayoutInflater.from(mContext);

v = inflater.inflate(R.layout.layout_appinfo, null);

}



// load controls from layout resources

ImageView ivAppIcon = (ImageView)v.findViewById(R.id.ivIcon);

TextView tvAppName = (TextView)v.findViewById(R.id.tvName);

TextView tvPkgName = (TextView)v.findViewById(R.id.tvPack);



// set data to display

ivAppIcon.setImageDrawable(entry.loadIcon(mPackManager));

tvAppName.setText(entry.loadLabel(mPackManager));

tvPkgName.setText(entry.packageName);



// return view

return v;

}



}
Utilities.java


Código:
public class Utilities {



/*

 * Get all installed application on mobile and return a list

 * @paramcContext of application

 * @returnlist of installed applications

 */

public static List<ApplicationInfo> getInstalledApplication(Context c) {

return c.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);

}



/*

 * Launch an application

 * @paramcContext of application

 * @parampmthe related package manager of the context

 * @parampkgNameName of the package to run

 */

public static boolean launchApp(Context c, PackageManager pm, String pkgName) {

// query the intent for lauching 

Intent intent = pm.getLaunchIntentForPackage(pkgName);

// if intent is available

if(intent != null) {

try {

// launch application

c.startActivity(intent);

// if succeed

return true;



// if fail

} catch(ActivityNotFoundException ex) {

// quick message notification

Toast toast = Toast.makeText(c, "Application Not Found", Toast.LENGTH_LONG);

// display message

toast.show();

}

}

// by default, fail to launch

return false;

}

}
layout_main.xml

Código:
 <?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"
    >
    <Button
android:id="@+id/Example Button"
android:text="Caca"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<GridView
android:id="@+id/lvApps"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>

</LinearLayout>
layout_appinfo.xml

Código:
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="?android:attr/listPreferredItemHeight"
  android:padding="5dip"  
  >
  
  <ImageView
      android:id="@+id/ivIcon"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:layout_marginRight="5dip"
      android:scaleType="center"
  />
  
  <LinearLayout
      android:orientation="vertical"
      android:layout_width="0dip"
      android:layout_height="fill_parent" 
      android:layout_weight="1"     
  >
  
      <TextView
          android:id="@+id/tvName"
          android:layout_width="fill_parent"
          android:layout_height="0dip"
          android:layout_weight="1"
          android:gravity="center_vertical"          
      /> 
  </LinearLayout>
</LinearLayout>
Para no ocupar mucho mas espacio he eliminado los imports y el package name.
Espero vuestra ayuda! ;)

Última edición por wolfcat90 Día 02/07/13 a las 12:28:52
Responder Con Cita


  #2  
Viejo 04/07/13, 14:11:41
Avatar de wolfcat90
wolfcat90 wolfcat90 no está en línea
Desarrollador
Mensajes: 445
 
Fecha de registro: jun 2012
Mensajes: 445
Modelo de smartphone: Samsung Galaxy Trend Plus
Versión de ROM: Stock
Tu operador: Movistar
Mencionado: 4 comentarios
Tagged: 1 hilos
En serio nadie puede ayudarme?
Responder Con Cita
  #3  
Viejo 04/07/13, 14:41:06
Avatar de kriogeN
kriogeN kriogeN no está en línea
Colaborador/a
Mensajes: 4,637
Compra y venta: (1)
 
Fecha de registro: oct 2010
Localización: Murcia
Mensajes: 4,637
Modelo de smartphone: Samsung Galaxy S7 Edge SM-G935F
Versión de ROM: CM13 - CM 11
Tu operador: Vodafone
Mencionado: 60 comentarios
Tagged: 3 hilos
Prueba poniendo esto en el Layout Main dentro del GridView

android:numColumns="2"

Y si funciona ya lo cambias por el número que quieras.
Responder Con Cita
  #4  
Viejo 04/07/13, 15:03:54
Avatar de wolfcat90
wolfcat90 wolfcat90 no está en línea
Desarrollador
Mensajes: 445
 
Fecha de registro: jun 2012
Mensajes: 445
Modelo de smartphone: Samsung Galaxy Trend Plus
Versión de ROM: Stock
Tu operador: Movistar
Mencionado: 4 comentarios
Tagged: 1 hilos
Cita:
Originalmente Escrito por kriogeN Ver Mensaje
Prueba poniendo esto en el Layout Main dentro del GridView

android:numColumns="2"

Y si funciona ya lo cambias por el número que quieras.
Muchisimas Gracias por responder, he preguntado en numerosos foros y eres la primera persona que me da una respuesta espero que funcione!
Responder Con Cita
Respuesta

Estás aquí
Regresar   HTCMania > Todo sobre Android > Programación y Desarrollo para Android


Reglas de Mensajes
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Las caritas están On
Código [IMG] está On
Código HTML está Off

Saltar a Foro



Hora actual: 07:17:24 (GMT +1)

Cookies settings
Powered by vBulletin™
Copyright © vBulletin Solutions, Inc. All rights reserved.
 
HTCMania: líderes desde el 2007