Android GridView

释放双眼,带上耳机,听听看~!
package com.imooc.www.moocdemo;
import android.app.Application;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.sax.StartElementListener;
import android.support.design.widget.NavigationView;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2016/5/10.
*/
public class GridViewActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener,AdapterView.OnItemClickListener {
private GridView gridView;
private List<Map<String,Object>> dataList;
private int[]icon={R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher};
private String[]iconName = {"逗你玩1","逗你玩2","逗你玩3","逗你玩4","逗你玩5","逗你玩1","逗你玩2","逗你玩3","逗你玩4","逗你玩5","逗你玩1","逗你玩2","逗你玩3","逗你玩4","逗你玩5","逗你玩1","逗你玩2","逗你玩3","逗你玩4","逗你玩5"};
private SimpleAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
gridView = (GridView) findViewById(R.id.gridview);
//准备数据源
dataList = new ArrayList<Map<String, Object>>();
//     getListData();
//参数很多 注意顺序
adapter = new SimpleAdapter(this,getListData(),R.layout.griditem,new String[]{"imag","text"},new int[]{R.id.gridimg,R.id.icname});
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(this);
}
private List<Map<String,Object>> getListData(){
for(int i=0;i<iconName.length;i++){
//map键值对        
 Map<String,Object>map = new HashMap<String,Object>();
map.put("imag",icon[i]);
map.put("text",iconName[i]);
dataList.add(map);
}
return dataList;
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
return false;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),""+position,Toast.LENGTH_LONG).show();
}
}

人已赞赏
Android文章

Android SplashScreen 欢迎界面

2020-3-31 16:47:04

Android文章

Android ActionBar

2020-3-31 18:01:48

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索