我正在开发一个有ListView... 的对话框
我已成功将适配器,选择器,list_itemlayout放入onCreate()如下..
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.variable_dialog);
lv=(ListView) findViewById(R.id.VariableslistView1);
lv.setAlwaysDrawnWithCacheEnabled(true);
final ArrayAdapter<String> ad=new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_1,Program.get().symboltable.getSymbols());
lv.setAdapter(ad);
lv.setSelector(R.drawable.item_selected);
Run Code Online (Sandbox Code Playgroud)
但每当我试图得到getSelectedItemPosition()它时,它总是返回-1
好像我没有选择任何东西..即使我如此调用我自己的选择:
lv.setSelected(true);
lv.setSelection(1);
lv.setItemChecked(1, true);
ad.notifyDataSetChanged();
ad.notifyDataSetInvalidated();
Run Code Online (Sandbox Code Playgroud)
这是我的选择器:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="2dp"
android:color="#FF00FF00" />
<gradient
android:angle="225"
android:endColor="#DD2ECCFA"
android:startColor="#DD000000" />
<corners
android:bottomLeftRadius="7dp"
android:bottomRightRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
为了上帝的缘故,到底是什么错误的?!?!
我甚至试过AdapterView.OnItemSelectedListener但从未成功:|
任何人都可以告诉我这是什么问题.
提前致谢
android android-arrayadapter android-listview android-dialog