Android------------BaseAdapter示例介绍
来源:互联网 发布:3乘3矩阵卷积运算 编辑:程序博客网 时间:2024/05/20 11:47
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /><ListView android:id="@+id/listview" android:layout_width="fill_parent" android:layout_height="wrap_content"></ListView></LinearLayout>
adapters.xml
<?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="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher"/><TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="aaaa"/></LinearLayout>
示例代码:
package com.tanghy.activity;import android.app.Activity;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.BaseAdapter;import android.widget.ListView;import android.widget.TextView;import android.widget.Toast;public class BaseAdapterTestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView listview = (ListView)findViewById(R.id.listview); listview.setAdapter(new myBaseAdapter()); listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {// TODO Auto-generated method stubToast.makeText(BaseAdapterTestActivity.this, "adsfadsf", Toast.LENGTH_SHORT).show();}}); } class myBaseAdapter extends BaseAdapter{@Overridepublic int getCount() {// TODO Auto-generated method stubreturn 10;}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubSystem.out.println("asdfasdfa");return null;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn 0;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubTextView textview = new TextView(getApplicationContext());convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.adapters, null);textview.setText("什么");return convertView;} }}
- Android------------BaseAdapter示例介绍
- 【Android】BaseAdapter示例
- Android BaseAdapter介绍和优化
- Android BaseAdapter介绍和优化
- Android的Adapter与BaseAdapter的介绍
- Android BaseAdapter 和ListAdapter的介绍
- BaseAdapter介绍
- BaseAdapter 使用示例
- Android --- BaseAdapter
- Android BaseAdapter
- android BaseAdapter
- Android BaseAdapter
- Android BaseAdapter
- Android BaseAdapter
- Android BaseAdapter
- Android中控件ListView列表控件baseadapter方法介绍
- BaseAdapter适配器实例介绍
- Android Handler详细介绍+示例
- ITIL学习(六)服务战略
- VIM插件安装路径
- C#版万年历
- Vector用法详解
- Max Sum
- Android------------BaseAdapter示例介绍
- NYOJ 479 欧拉函数
- 联动下拉框 jquery 插件(二)
- CSDN下载频道【2月热门资源TOP100】汇总
- 分页技术原理与实现(一)——为什么要进行分页及怎么分页
- java常用类库(上)
- 第一章 写作初衷——若是当年早知道......
- 联动下拉框 jquery 插件(一)
- http get 方式参数的长度限制