public class ListFrag extends ListFragment {
public myadaputer adapter;
public List<String> data;
public void setData(List<String> data) {
this.data = data;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new myadaputer();
adapter.setDate(getdata());
}
public List<String> getdata(){
Bundle ig = getArguments();
int size = ig.getInt("size");
List<String> x = new ArrayList<String>();
for(int i=0;i< size ;i++) {
x.add("add" + i);
}
return x;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.listfrag_layout, null);
setListAdapter(adapter);
return view;
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Toast.makeText(getActivity(), "onListItemClick", Toast.LENGTH_SHORT).show();
}
class myadaputer extends BaseAdapter {
private List<String> data;
public void setDate(List<String> data) {
this.data = data;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if(convertView == null){
view = LayoutInflater.from(getActivity()).inflate(R.layout.listview,null);
}else{
view = convertView;
}
TextView tv = (TextView) view.findViewById(R.id.textView);
tv.setText(data.get(position).toString());
return view;
}
}
}
0 件のコメント:
コメントを投稿