-1
我想知道是否有可能使用类似的东西在runnable中创建列表视图?有人能给我举个例子吗?谢谢。是否有可能使用run()创建一个ListView?
public void testBtnListViewClick(View v) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
LinearLayout ll = new LinearLayout(this);
ListView lv = new ListView(this);
String[] values = new String[10];
for(int i=0;i<10;i++){
values[i] = ""+i;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, values);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
Toast.makeText(getBaseContext(), ""+arg2,Toast.LENGTH_SHORT).show();
Log.d("DEBUG", ""+arg2);
}
});
//ll.addView(lv);
ll.addView(lv, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
setContentView(ll);
}
}
但它不会允许我添加这一行LinearLayout ll = new LinearLayout(this); \t \t \t ListView lv = new ListView(this); ArrayAdapter adapter = new ArrayAdapter (this,R.layout.list_item,values); –
AuroraBlaze
它的说法是什么异常? –
其下划线上的红线“new LinearLayout(this);” ,“新的LinearLayout(this);”和“new ArrayAdapter(this,R.layout.list_item,values);”当我把鼠标悬停在它上面时,它说“构造函数LinearLayout(new Runnable(){})未定义”,“构造函数LinearLayout(new Runnable(){})未定义”,而且“构造函数ArrayAdapter (新的Runnable(){},int,字符串[])是不确定的“,这是什么让我想知道是否我可以使用它内部运行 –
AuroraBlaze