stopped
package com.example.gridview;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
private GridView gridView;
private List<Map<String, Object>> dataList;
private int[] icon = { R.drawable.address_book, R.drawable.calendar,
R.drawable.camera, R.drawable.clock, R.drawable.games_control,
R.drawable.messenger, R.drawable.ringtone, R.drawable.settings,
R.drawable.speech_balloon, R.drawable.weather, R.drawable.world,
R.drawable.youtube };
private String[] iconName = { "聯系人", "日歷", "照相機", "時鐘", "游戲", "短信", "鈴聲",
"設置", "語音", "天氣", "瀏覽器", "Youtube" };
private SimpleAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gridView = (GridView) findViewById(R.id.gridView);
dataList = new ArrayList<Map<String, Object>>();
//getData();
adapter = new SimpleAdapter(this, getData(), R.layout.item,
new String[] { "image", "text" }, new int[] { R.id.image,
R.id.text });
gridView.setAdapter(adapter);
}
private List<Map<String, Object>> getData() {
// TODO Auto-generated method stub
for (int i = 0; i < icon.length; i++) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("image", icon[i]);
map.put("text", iconName[i]);
dataList.add(map);
}
return dataList;
}
}
2016-08-10
別改主題,我改了主題以后也會stopped
2016-06-30
第一個布局文件里的ImageView里,src的值應該是@drawable,不應該是@+id,錯誤原因應該是這個
2016-06-28
<?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" >
? ??
? ? <GridView
? ? ? ? android:layout_marginTop="10dp"
? ? ? ? android:id="@+id/gridView"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:numColumns="3"
? ? ? ? android:horizontalSpacing="10dp"
? ? ? ? android:verticalSpacing="10dp"
? ? ? ? />
</LinearLayout>
2016-06-28
<?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"?
? ? android:gravity="center"
? ? android:background="#000000"
? ? >
? ? <ImageView
? ? ? ? android:id="@+id/image"
? ? ? ? android:src="@+id/image"
? ? ? ? android:layout_width="60dp"
? ? ? ? android:layout_height="60dp"
? ? ? ? />
<TextView?
? ? android:id="@+id/text"
? ? android:layout_marginTop="5dp"
? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:textColor="#ffffff"
? ? ? ? android:text="文字"
? ? />
</LinearLayout>
2016-06-28
我看錯誤信息上寫著好像是XML布局文件有問題,你把布局文件也發一下
2016-06-28
你的代碼我還原了一下,沒有錯誤哦,親。請不要發往問答區。