首先新建一个XXAdapter文件
package com.example.app.ui.win;调用
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.app.model.ThingType;
import java.util.List;
public class ThingTypeSpinnerAdapter extends BaseAdapter {
private List<ThingType> tts;
private Activity activity;
public ThingTypeSpinnerAdapter(List<ThingType> tts, Activity activity){
this.tts = tts;
this.activity = activity;
}
@Override
public int getCount() {
return tts.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
TextView textView = new TextView(activity);
textView.setText(tts.get(i).getType());
textView.setTextSize(18);
return textView;
}
}
List<ThingType> list = GsonUtil.toList(result.getString("data2"), ThingType.class);
BaseAdapter adapter=new XXAdapter(list,getActivity());
thingtype.setAdapter(adapter);
thingtype.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
thingtypeId=list.get(i).getId();
Toast.makeText(getActivity(),"你选择的是"+list.get(i).getId().toString(),Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
- 本文标题: Spinner 动态创建数据Item
- 文章分类:【Android】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
- 上一篇:android多行文本输入框
- 下一篇: Spinner 写静态数据Item