@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
info.WebGet();
nations=info.initData(); //这个有数据,这里没有问题
NationSpinner=(Spinner) findViewById(R.id.NationText);
MyAdapter myAdapter=new MyAdapter(this,loadRes,nations);
NationSpinner.setAdapter(myAdapter);
NationSpinner.setOnItemSelectedListener(myAdapter);
}
上面是Activity的代码,
下面是 适配器的类;
public class MyAdapter extends BaseAdapter implements OnItemSelectedListener {
Context context;
ArrayList<Nation> list=new ArrayList<Nation>();
private Handler handler;
public MyAdapter(Context con,Handler handler,ArrayList<Nation> list){
this.list=list;
context=con;
this.handler=handler;
}
@Override
public int getCount() {
android.util.Log.i("t460470591", "getCount");
return list.size();
}
@Override
public Nation getItem(int position) {
android.util.Log.i("t460470591", "getItem");
return list.get(position);
}
@Override
public long getItemId(int position) {
android.util.Log.i("t460470591", "getItemId");
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
android.util.Log.i("t460470591", "getView "+position);
Nation o=list.get(position);
View view=View.inflate(context, R.layout.item_listview,null);
TextView tView=(TextView) view.findViewById(R.id.nation_id);
TextView tViewD=(TextView) view.findViewById(R.id.nation_text);
tView.setText(o.getNationid()+"");
tViewD.setText(o.getNationtext()+"");
return view;
}
@Override //执行不了这个方法
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
android.util.Log.i("t460470591", "onItemSelected");
TextView iDTextView=(TextView) arg1.findViewById(R.id.nation_id);
TextView TextView=(TextView) arg1.findViewById(R.id.nation_text);
Bundle bundle=new Bundle();
bundle.putString(WebSerState.Operate, WebSerState.GetNation);
bundle.putString(WebSerState.NationID, iDTextView.getText().toString().trim());
bundle.putString(WebSerState.NationText,TextView.getText().toString().trim());
Message msgMessage=new Message();
msgMessage.what=WebSerState.Other;
msgMessage.setData(bundle);
handler.sendMessage(msgMessage);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
android.util.Log.i("t460470591", "onNothingSelected");
}
}
------解决方案--------------------
在R.layout.item_listview 这个布局文件里面 加入下面的标签试试,可能是没有焦点。
android:descendantFocusability="blocksDescendants"
android:focusable="false"