标签:protected xtend and sim code pat items adapter imp
安卓中adapter分为ArrayAdapter和baseAdapter;其中简单的ArrayAdapter主要用于简单的文本字符串的实现。
实现创建适配器adapter的主要步骤:
1、创建视图ListView
2、创建数据源items ArrayList<String> items = new ArrayList<>();
3、创建适配器adapter,并且绑定数据源Items adapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,items);
4、将适配器adapter绑定在视图ListView上
public class MainActivity extends AppCompatActivity {
ArrayList<String> items = new ArrayList<>();
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv =(ListView) findViewById(R.id.listName);
adapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,items);
lv.setAdapter(adapter);
}
}
标签:protected xtend and sim code pat items adapter imp
原文地址:https://www.cnblogs.com/twinklePassion/p/10117085.html