标签:
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设置响应事件的时候,获取点击对象。
标签:
原文地址:http://www.cnblogs.com/rain-tl/p/4808408.html