GridView的用法和ListView一样
java代码
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_view);
this.newsList();
}
private void newsList() {
Intent i = getIntent();
title = i.getStringExtra("title");
url = i.getStringExtra("url");
Log.i("joy", url);
TextView textView1 = (TextView) findViewById(R.id.textView1);
textView1.setText(title);
/**
* 设置返回button
*
*/
ImageButton imageButton = (ImageButton) findViewById(R.id.button_back);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// ODO Auto-generated method stub
finish();
}
});
list = (GridView) findViewById(R.id.gridview);
mylist = new ArrayList<Map<String, Object>>();
SimpleAdapter mSchedule = new SimpleAdapter(this, mylist,
R.layout.grid_view_list, new String[] { "url",
"title" }, new int[] { R.id.ItemImage, R.id.ItemText });
list.setAdapter(mSchedule);
init();
new GetTask().execute(url);
}
grid_view.xml
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:background="@drawable/web_bg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
grid_view_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:paddingBottom="4dip" android:layout_width="fill_parent">
<ImageView
android:layout_height="wrap_content"
android:id="@+id/ItemImage"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_below="@+id/ItemImage"
android:layout_height="wrap_content"
android:text=""
android:textColor="#FF000000"
android:layout_centerHorizontal="true"
android:id="@+id/ItemText">
</TextView>
</RelativeLayout>