我正在尝试弄清楚如何将一个contentDescription添加到ListView,因为它正在填充。我看一个答案,但不知道如何实现它。这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawerLayout=(DrawerLayout) findViewById(R.id.drawerLayout);
drawerListener = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer,
R.string.drawer_open, R.string.drawer_close){
public void onDrawerOpen(View drawerView){
super.onDrawerOpened(drawerView);
}
public void onDrawerClosed(View drawerView){
super.onDrawerClosed(drawerView);
}
};
drawerLayout.setDrawerListener(drawerListener);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
planets=getResources().getStringArray(R.array.planets); //get planets array
listView=(ListView) findViewById(R.id.drawerList);
//Set ArrayAdapter
listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, planets ));
//set onClickListener for array
listView.setOnItemClickListener(this);
}
感谢;
答案 0 :(得分:0)
ArrayAdapter没有这样做。你必须扩展它,如下:
用listView.setAdapter(...
代替:
listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, planets ){
@Override
public View getView (int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
v.setContentDescription(... value ...);
return v;
}
});