package com.GridView2;
import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;
//android:padding="30dp"
// android:verticalSpacing="30dp"
// android:horizontalSpacing="30dp"
public class gridviewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new GridViewAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
TextView textview = (TextView) v;
Toast.makeText(gridviewActivity.this, "" + position+textview.getText().toString(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(gridviewActivity.this, textviewActivity.class );
intent.putExtra("text", textview.getText().toString());
startActivity(intent);
}
});
}
public class GridViewAdapter extends BaseAdapter {
private Context mContext;
public GridViewAdapter(Context c) {
mContext = c;
}
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView;
if (convertView == null) {
textView = new TextView(mContext);
} else {
textView = (TextView) convertView;
}
// imageView.setImageResource(mImageResourceIds[position]);
String s = (char) (position + 65) + "";
textView.setText(s);
textView.setGravity( Gravity.CENTER );
return textView;
}
public int getCount() {
return 26;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
}
}
///////////////////////////////////////////////////////////////
package com.GridView2;
import android.app.*;
import android.content.*;
import android.os.*;
import android.widget.*;
public class textviewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.textviews);
// TODO Auto-generated method stub
TextView textview = (TextView)findViewById( R.id.textView1 );
Intent intent = getIntent();
String s = intent.getStringExtra("text");
textview.setText(s);
//textview.setText(resid);
}
}
///////////////////////////////////////////////////////////////
// main.xml
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview" android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="auto_fit"
android:columnWidth="60dp"
android:gravity="center"
android:verticalSpacing="30dp"
android:horizontalSpacing="34dp"
android:stretchMode="columnWidth"
android:background="#ffff"
>
</GridView>
//////////////////////////////////////////////////////////////////
// textview.xml
<?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">
<TextView android:gravity="center" android:textSize="150pt" android:text="" android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="fill_parent"></TextView>
</LinearLayout>