标签:adapter base 索引 cti str 技术 rri bsp his
简单 继承BaseAdapter:
Myadapter代码:
public class Myadapter extends BaseAdapter { private Context context; private String[] ss; /* private List<User>list;*/ public Myadapter(Context context,String[] ss){ super(); this.context=context; this.ss=ss; } @Override //得到个数 public int getCount() { return ss.length; } @Override //得到所以索引,即i值 public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { String str=ss[position]; TextView textView=new TextView(context); textView.setText(str); return textView; } }
MianActivity:
public class MainActivity extends AppCompatActivity { private String[] ss=new String[]{ "山西","太原","山东","贵阳","天津","北京","洪湖" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView = (ListView) findViewById(R.id.list_view); Myadapter adapter=new Myadapter(this,ss); // ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,ss); listView.setAdapter(adapter); } }
进阶baseAdatapter:
标签:adapter base 索引 cti str 技术 rri bsp his
原文地址:https://www.cnblogs.com/goodshred/p/9772847.html