I want to develop the same type of view we have in android for the slection of an application by using a gridview of linearlayouts. Each linear layour is composed of an image and a text.
XML code for the GridLayout
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <GridView xmlns:android="http://schemas.android.com/apk/res/android"
- id="@+id/myGrid"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:numColumns="3"
- android:gravity="center"
- />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
XML code for the LinearLayout
Using xml Syntax Highlighting
- <?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">
- <ImageView id="@+id/image"
- android:layout_width="fill_parent"
- android:layout_height="50px"
- android:layout_marginTop="10px"
- android:layout_marginLeft="10px"
- android:layout_marginRight="10px"
- />
- <TextView id="@+id/imagetext"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="15px"/>
- </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
Those XML are use by an activity that create a set of view and use an adapter to populate the gridview
Using java Syntax Highlighting
- public class SetupContent extends Activity {
- @Override
- public void onCreate(Bundle icicle){
- super.onCreate(icicle);
- setContentView(R.layout.imagegrid);
- GridView g = (GridView) findViewById(R.id.myGrid);
- g.setAdapter(new ImageAdapter(this));
- }
- public class CustomImageView extends LinearLayout
- implements android.view.View.OnClickListener,android.view.View.OnFocusChangeListener{
- public void onFocusChanged(View v, boolean focused) {
- // TODO Auto-generated method stub
- if(focused)
- this.setBackground(R.drawable.shape_1);
- else
- this.setBackground(0x000000);
- }
- ImageView image =null;
- TextView label =null;
- View theView =null;
- int ID =0;
- public CustomImageView(Context context) {
- super(context);
- // TODO Auto-generated constructor stub
- ViewInflate inf =(ViewInflate)getSystemService(INFLATE_SERVICE);
- theView = inf.inflate(R.layout.imageview, null, false, null);
- image = (ImageView) theView.findViewById(R.id.image);
- label = (TextView) theView.findViewById(R.id.imagetext);
- label.setTypeface(Typeface.create("Tahoma", Typeface.BOLD));
- addView(theView, new LinearLayout.LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
- setOnClickListener(this);
- this.setOnFocusChangeListener(this);
- }
- @Override
- public boolean onMotionEvent(MotionEvent event) {
- performClick();
- requestFocus();
- return super.onMotionEvent(event);
- }
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- Log.i("IconTextMenuClicked", "clicked");
- label.setText("xxx");
- SetupContent(ID);
- arg0.requestFocus();
- }
- public void setImageResource(int drawable)
- {
- image.setImageResource(drawable);
- }
- public void setImageLabel(String strLabel)
- {
- label.setText(strLabel);
- }
- public void setID(int nID)
- {
- ID=nID;
- }
- }
- public class ImageAdapter extends BaseAdapter {
- private Integer[] mThumbIds = {
- R.drawable.people_add32x32,
- R.drawable.appointmentnew32x32,
- R.drawable.people32x32,
- R.drawable.people_add32x32,
- R.drawable.appointmentnew32x32,
- R.drawable.people32x32,
- R.drawable.people_add32x32,
- R.drawable.appointmentnew32x32,
- R.drawable.people32x32,
- R.drawable.people_add32x32,
- R.drawable.appointmentnew32x32,
- R.drawable.people32x32,
- R.drawable.people_add32x32,
- R.drawable.appointmentnew32x32,
- R.drawable.people32x32,
- R.drawable.people_add32x32,
- R.drawable.appointmentnew32x32,
- R.drawable.people32x32,
- R.drawable.people_add32x32,
- R.drawable.appointmentnew32x32,
- R.drawable.people32x32,
- R.drawable.people_add32x32,
- R.drawable.appointmentnew32x32,
- R.drawable.people32x32,
- R.drawable.people_add32x32,
- R.drawable.appointmentnew32x32,
- R.drawable.people32x32
- };
- private String[] labels = {
- "Contacts",
- "none...",
- "none...",
- "Contacts",
- "none...",
- "none...",
- "Contacts",
- "none...",
- "none...",
- "Contacts",
- "none...",
- "none...",
- "Contacts",
- "none...",
- "none...",
- "Contacts",
- "none...",
- "none...",
- "Contacts",
- "none...",
- "none...",
- "Contacts",
- "none...",
- "none...",
- "Contacts",
- "none...",
- "none..."
- };
- public ImageAdapter(Context c) {
- mContext = c;
- }
- public int getCount(){
- return mThumbIds.length;
- }
- public Object getItem(int position){
- return position;
- }
- public long getItemId(int position){
- return position;
- }
- public View getView(int position, View convertView, ViewGroup parent) {
- CustomImageView i = new CustomImageView(mContext);
- i.setImageResource(mThumbIds[position]);
- i.setID(position);
- String label = "img" + position;
- i.setImageLabel(label);
- return i;
- }
- private Context mContext;
- }
- void SetupContent(int ID)
- {
- switch(ID){
- case 0:
- SetupContactContent();
- break;
- }
- }
- void SetupContactContent()
- {
- }
- }
Parsed in 0.049 seconds, using GeSHi 1.0.8.4
I want that when I move the cursor arrow... or when I click on a icon the background change from black to a countour of type shape and the focus move to this cell. Instead of this i get:
If a move with the arrow keys the background remain the standard one (blu and big sqare).
If I clik the background dont change and the focus remain on the current cell, only the label is changed to xxx
here is the shape I want to use as background.
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="UTF-8"?>
- <shape
- xmlns:android="http://schemas.android.com/apk/res/android">
- <solid android:color="#00000000"/>
- <stroke android:width="4dp" android:color="@color/butter_dark"/>
- <gradient
- android:startColor="#9297e9"
- android:endColor="#3742e9"
- android:angle="270"/>
- <padding android:left="1dp" android:top="1dp"
- android:right="1dp" android:bottom="1dp" />
- <corners android:radius="3dp" />
- </shape
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

