简单的自定义Adapter

 1 import android.content.Context;
 2 import android.view.LayoutInflater;
 3 import android.view.View;
 4 import android.view.ViewGroup;
 5 import android.widget.BaseAdapter;
 6 import android.widget.ImageView;
 7 import android.widget.TextView;
 8 import android.widget.Toast;
 9 
10 import com.example.administrator.yunphone.R;
11 import java.util.List;
12 
13 /**
14  * Created by Administrator on 2016/7/13.
15  */
16 public class PhoneNumAdapter extends BaseAdapter implements View.OnClickListener {
17     private List<String> mList;
18     private Context context;
19     private LayoutInflater layoutInflater;
20 
21     public PhoneNumAdapter(Context context, List phoneList){
22         this.context=context;
23         this.mList=phoneList;
24         layoutInflater=LayoutInflater.from(context);
25     }
26     @Override
27     public int getCount() {
28         return mList.size();
29     }
30 
31     @Override
32     public Object getItem(int i) {
33         return mList.get(i);
34     }
35 
36     @Override
37     public long getItemId(int i) {
38         return i;
39     }
40 
41     @Override
42     public View getView(int i, View view, ViewGroup viewGroup) {
43         View v;
44         if(view!=null){
45             v=view;
46         }else {
47             v=layoutInflater.inflate(R.layout.call_item,viewGroup,false);
48         }
49         TextView textView= (TextView) v.findViewById(R.id.item_view);
50         textView.setText(mList.get(i));
51         ImageView imageView= (ImageView) v.findViewById(R.id.item_down);
52         imageView.setOnClickListener(this);
53         return v;
54     }
55 
56     @Override
57     public void onClick(View view) {
58         Toast.makeText(context,"尚未完成",Toast.LENGTH_SHORT).show();
59     }
60 }

 

posted @ 2016-07-13 17:37  点滴之水  阅读(253)  评论(0编辑  收藏  举报