android BaseAdapter例子

xiaoxiao2021-03-01  12

public class ListTestActivity extends Activity { ListView mListView; Map<Integer, String> mMapContent; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mMapContent = new HashMap<Integer, String>(); mListView = (ListView)findViewById(R.id.listview); mListView.setAdapter(new MyListAdapter(this, 20)); } class MyListAdapter extends BaseAdapter { int mCount; Context mContext; public MyListAdapter(Context context, int count) { mCount = count; mContext = context; } public int getCount() { return mCount; } public Object getItem(int arg0) { return arg0; } public long getItemId(int arg0) { return arg0; } public View getView(int position, View convertView, ViewGroup arg2) { ViewHold holder = null; if(convertView == null) { convertView = LinearLayout.inflate(mContext, R.layout.list_item, null); holder = new ViewHold(convertView); convertView.setTag(holder); } else { holder = (ViewHold)convertView.getTag(); } holder.position = position; holder.textView.setText("listitem" + position + ":"); holder.editText.setText(mMapContent.get(position));//Integer.valueOf(position) return convertView; } class ViewHold { TextView textView; EditText editText; int position; public ViewHold(View v) { textView = (TextView)v.findViewById(R.id.textview); editText = (EditText)v.findViewById(R.id.edittext); editText.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { mMapContent.put(position, s.toString()); } }); } } } } 相关资源:敏捷开发V1.0.pptx
转载请注明原文地址: https://www.6miu.com/read-4050126.html

最新回复(0)