Android APP開發活用範例速查大辭典(Ch0202-GridView顯示格線)

Android APP開發活用範例速查大辭典(Ch0202-GridView顯示格線)

Android APP開發活用範例速查大辭典(Ch0202-GridView顯示格線)

 

GUI-XML片段

<GridView
android:id=”@+id/gridView”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:horizontalSpacing=”10dp”
android:numColumns=”4″
android:verticalSpacing=”10dp” />

 

程式碼片段

public class Ch0202 extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ch0202_main);
GridView gridView = (GridView) findViewById(R.id.gridView);

// 建立Adapter
ListAdapter adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, WEEK);
// 設定Adapter
gridView.setAdapter(adapter);
}

// 要在ListView所顯示的字串
private static final String[] WEEK = new String[] { “一”, “二”, “三”, “四”,
“五”, “六”, “日” };
}

 

PS

01.如果要在gridview中自訂內容,請在GOOGLE 查詢『android gridview image text example

 

 

 


發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *