Descargar la siguiente imagen.
Icono Celular
Creamos un archivo colors.xml dentro de la carpeta values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#ff0000</color>
<color name="green">#00ff00</color>
<color name="blue">#0000ff</color>
<color name="orange">#ff6000</color>
<color name="white">#ffffff</color>
<color name="black">#000000</color>
<color name="light_gray">#dddddd</color>
</resources>
Nuevo layout de nombre "master_layout" en la carpeta layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/txtNuevoBoton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/lblTitulo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="@android:color/white" />
<LinearLayout
android:id="@+id/lytLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0"
android:background="@android:color/white">
</LinearLayout>
<ImageButton
android:src="@drawable/ic_launcher"
android:id="@+id/imgLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Creamos una nueva clase Boton
package edu.sise.customviews;
import android.view.View.OnClickListener;
public class Boton {
private int imageId;
private String textoGrande;
private String textoChico;
private OnClickListener onClickListener;
public Boton (String textoGrande, String textoChico, OnClickListener onClickListener){
this.textoGrande = textoGrande;
this.textoChico = textoChico;
this.onClickListener = onClickListener;
}
public int getImageId() {
return imageId;
}
public void setImageId(int imageId) {
this.imageId = imageId;
}
public String getTextoGrande() {
return textoGrande;
}
public void setTextoGrande(String textoGrande) {
this.textoGrande = textoGrande;
}
public String getTextoChico() {
return textoChico;
}
public void setTextoChico(String textoChico) {
this.textoChico = textoChico;
}
public OnClickListener getOnClickListener() {
return onClickListener;
}
public void setOnClickListener(OnClickListener onClickListener) {
this.onClickListener = onClickListener;
}
}
Creamos un nuevo layout "boton_view"
<?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="wrap_content">
<ImageView
android:id="@+id/imgLogo"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="0"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="@+id/txtTitulo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="@android:style/TextAppearance.Large" />
<TextView
android:id="@+id/txtSubitulo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Small" />
</LinearLayout>
</LinearLayout>
Creamos una clase BotonAdapter
package com.custom.components;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.custom.R;
public class BotonAdapter extends ArrayAdapter<Boton> {
private final Context context;
private final ArrayList<Boton> values;
public BotonAdapter(Context context, ArrayList<Boton> values) {
super(context, R.layout.boton_view, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vistaFila = inflater.inflate(R.layout.boton_view, parent, false);
TextView txtTitulo = (TextView) vistaFila.findViewById(R.id.txtTitulo);
TextView txtSubTitulo = (TextView) vistaFila.findViewById(R.id.txtSubitulo);
Boton boton = values.get(position);
txtTitulo.setText(boton.getTextoGrande());
txtSubtitulo.setText(boton.getTextoChico());
return vistaFila;
}
}
Activity MasterActivity
package edu.sise.customviews;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.LinearLayout;
import android.widget.ListView;
public class MasterActivity extends Activity {
ArrayList<Boton> botones;
BotonAdapter adptBotones;
LinearLayout layoutContenido;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.master_layout);
layoutContenido = (LinearLayout) findViewById(R.id.lytLayout);
botones = new ArrayList<Boton>();
for (int i = 0; i < 20; i++) {
Boton boton = new Boton("Boton " + i, "Ejecuta acciones", null);
botones.add(boton);
}
adptBotones = new BotonAdapter(this, botones);
ListView lvBotones = new ListView(this);
lvBotones.setAdapter(adptBotones);
layoutContenido.addView(lvBotones);
}
}
Icono Celular
Creamos un archivo colors.xml dentro de la carpeta values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#ff0000</color>
<color name="green">#00ff00</color>
<color name="blue">#0000ff</color>
<color name="orange">#ff6000</color>
<color name="white">#ffffff</color>
<color name="black">#000000</color>
<color name="light_gray">#dddddd</color>
</resources>
Nuevo layout de nombre "master_layout" en la carpeta layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/txtNuevoBoton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/lblTitulo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="@android:color/white" />
<LinearLayout
android:id="@+id/lytLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0"
android:background="@android:color/white">
</LinearLayout>
<ImageButton
android:src="@drawable/ic_launcher"
android:id="@+id/imgLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Creamos una nueva clase Boton
package edu.sise.customviews;
import android.view.View.OnClickListener;
public class Boton {
private int imageId;
private String textoGrande;
private String textoChico;
private OnClickListener onClickListener;
public Boton (String textoGrande, String textoChico, OnClickListener onClickListener){
this.textoGrande = textoGrande;
this.textoChico = textoChico;
this.onClickListener = onClickListener;
}
public int getImageId() {
return imageId;
}
public void setImageId(int imageId) {
this.imageId = imageId;
}
public String getTextoGrande() {
return textoGrande;
}
public void setTextoGrande(String textoGrande) {
this.textoGrande = textoGrande;
}
public String getTextoChico() {
return textoChico;
}
public void setTextoChico(String textoChico) {
this.textoChico = textoChico;
}
public OnClickListener getOnClickListener() {
return onClickListener;
}
public void setOnClickListener(OnClickListener onClickListener) {
this.onClickListener = onClickListener;
}
}
Creamos un nuevo layout "boton_view"
<?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="wrap_content">
<ImageView
android:id="@+id/imgLogo"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="0"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="@+id/txtTitulo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="@android:style/TextAppearance.Large" />
<TextView
android:id="@+id/txtSubitulo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Small" />
</LinearLayout>
</LinearLayout>
Creamos una clase BotonAdapter
package com.custom.components;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.custom.R;
public class BotonAdapter extends ArrayAdapter<Boton> {
private final Context context;
private final ArrayList<Boton> values;
public BotonAdapter(Context context, ArrayList<Boton> values) {
super(context, R.layout.boton_view, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vistaFila = inflater.inflate(R.layout.boton_view, parent, false);
TextView txtTitulo = (TextView) vistaFila.findViewById(R.id.txtTitulo);
TextView txtSubTitulo = (TextView) vistaFila.findViewById(R.id.txtSubitulo);
Boton boton = values.get(position);
txtTitulo.setText(boton.getTextoGrande());
txtSubtitulo.setText(boton.getTextoChico());
return vistaFila;
}
}
Activity MasterActivity
package edu.sise.customviews;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.LinearLayout;
import android.widget.ListView;
public class MasterActivity extends Activity {
ArrayList<Boton> botones;
BotonAdapter adptBotones;
LinearLayout layoutContenido;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.master_layout);
layoutContenido = (LinearLayout) findViewById(R.id.lytLayout);
botones = new ArrayList<Boton>();
for (int i = 0; i < 20; i++) {
Boton boton = new Boton("Boton " + i, "Ejecuta acciones", null);
botones.add(boton);
}
adptBotones = new BotonAdapter(this, botones);
ListView lvBotones = new ListView(this);
lvBotones.setAdapter(adptBotones);
layoutContenido.addView(lvBotones);
}
}
Comentarios
Publicar un comentario