只有文字沒(méi)有圖片,有誰(shuí)知道嗎
public class MainActivity extends ActionBarActivity {
? ? private GridView gridview;
? ? private List<Map<String, Object>>dataList;
? ? private int[]jpg={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e,R.drawable.f,
? ? ? ? ? ? ?R.drawable.g,R.drawable.h,};
? ? private String[]text={"1號(hào)美女","2號(hào)美女","3號(hào)美女","4號(hào)美女","5號(hào)美女","6號(hào)美女","7號(hào)美女","8號(hào)美女"};
? ? private SimpleAdapter simpleadapter;
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? gridview=(GridView) findViewById(R.id.gridView1); ??
? ? ? ? /*
? ? ? ? ?* 數(shù)據(jù)源
? ? ? ? ?* 適配器
? ? ? ? ?* 加載
? ? ? ? ?* 監(jiān)聽(tīng)
? ? ? ? ?*/
? ? ? ? dataList=new ArrayList<Map<String,Object>>();
? ? ? ? ?getData();
? ? ? ? ?simpleadapter=new SimpleAdapter(this, dataList, R.layout.item, new String[]{"jgp","text"}, new int[]{R.id.imageView,R.id.textView});
? ? ? ? ?gridview.setAdapter(simpleadapter);
? ? ? ? ?
? ? ? ? ?
? ? }
? ? private List<Map<String, Object>> getData() {
? ?
? ? for(int i=0;i<8;i++)
? ? {
? ? Map<String, Object>map=new HashMap<String, Object>();
? ? map.put("jpg", jpg[i]);
? ? map.put("text", text[i]);
? ? dataList.add(map);
? ? }
return dataList;
// TODO Auto-generated method stub
}
}
2016-01-20
android studio中圖片調(diào)用方式是R.mipmap.jpg[i],
圖片文件在mipmap中,用這種方式調(diào)用
2016-01-18
<?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/imageView"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:src="@drawable/a"?
? ? ? ? />
? ? <TextView?
? ? ? ? android:id="@+id/textView"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="文字"
? ? ? ? android:textSize="20sp"
? ? ? ? android:textColor="#ffffff"
? ? ? ? />
</LinearLayout>