码迷,mamicode.com
首页 > 其他好文 > 详细

BaseAdapter

时间:2015-09-14 23:59:41      阅读:432      评论:0      收藏:0      [点我收藏+]

标签:

BaseAdapter是为ListView、GridView适配数据的抽象类

public class MainAdapter extends BaseAdapter{
     private LayoutInflater inflater;
     private Context        context;
     public MainAdapter(Context context){
            this.context=context;
            inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);        
    }
    @返回记录的数量
    public int getCount() {
        // TODO Auto-generated method stub
        return num;
    }

    @获取点击的条目数据
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @获取点击条目的ID
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @适配数据
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        // TODO Auto-generated method stub
        View view=inflater.inflate(R.layout.test, null);
        TextView tv_name=(TextView)view.findViewById(R.id.textView1);
        Button btn=(Button)view.findViewById(R.id.button1);
        tv_name.setText("标记");
        btn.setText("确认");
        return view;
    }


}
public class MainActivity extends Activity {
    GridView gridView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        GridView gridView = (GridView)findViewById(R.id.gridView1);
        gridView.setAdapter(new MainAdapter(this));

}
}

ProcessInfo info = (ProcessInfo) lv.getItemAtPosition(position);在为Item设置响应事件的时候,获取点击对象。

BaseAdapter

标签:

原文地址:http://www.cnblogs.com/rain-tl/p/4808408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!