編輯:關於Android編程
一、適配器 ListItemClickAdapter
public class ListItemClickAdapter extends BaseAdapter { private Context contxet; private ArrayListlist; private ListItemClickHelp callback; private LayoutInflater mInflater; public ListItemClickAdapter(Context contxet, ArrayList list, ListItemClickHelp callback) { this.contxet = contxet; this.list = list; this.callback = callback; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, final ViewGroup parent) { mInflater = (LayoutInflater) contxet .getSystemService(Context.LAYOUT_INFLATER_SERVICE); ViewHolder holder; if (convertView == null) { convertView = mInflater.inflate( R.layout.block_list_item, null); holder = new ViewHolder(); holder.mAd_tv_show = (TextView) convertView .findViewById(R.id.ad_tv_show); holder.mAd_btn_one = (Button) convertView .findViewById(R.id.ad_btn_one); holder.mAd_btn_two = (Button) convertView .findViewById(R.id.ad_btn_two); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.mAd_tv_show.setText(list.get(position)); final View view = convertView; final int p = position; final int one = holder.mAd_btn_one.getId(); holder.mAd_btn_one.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { callback.onClick(view, parent, p, one); } }); final int two = holder.mAd_btn_two.getId(); holder.mAd_btn_two.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { callback.onClick(view, parent, p, two); } }); return convertView; } public static class ViewHolder { TextView mAd_tv_show; Button mAd_btn_one; Button mAd_btn_two; } }
二、接口 ListItemClickHelp
/** * listview點擊事件接口 * @author Alan * */ public interface ListItemClickHelp { void onClick(View item, View widget, int position, int which); }
public class MainActivity extends Activity implements ListItemClickHelp { private TextView mtv_show; private ListView mlv_show; private ArrayListmdata = new ArrayList (); private ListItemClickAdapter madapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initLayout(); } private void initLayout() { mdata.add("One"); mdata.add("Two"); mdata.add("Three"); mdata.add("Four"); mdata.add("Five"); mdata.add("菠蘿"); mdata.add("蘋果"); mdata.add("葡萄"); mdata.add("哈密瓜"); mdata.add("香蕉"); mtv_show = (TextView) this.findViewById(R.id.tv_show); mlv_show = (ListView) this.findViewById(R.id.lv_show); madapter = new ListItemClickAdapter(this, mdata, this); mlv_show.setAdapter(madapter); mlv_show.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView> adapter, View view, int position, long arg3) { mtv_show.setText(mdata.get(position)); } }); } @Override public void onClick(View item, View widget, int position, int which) { switch (which) { case R.id.ad_btn_one: mtv_show.setText(mdata.get(position) + "Btn one"); break; case R.id.ad_btn_two: mtv_show.setText(mdata.get(position) + "Btn two"); break; default: break; } } }
五、下載地址:http://download.csdn.net/detail/shi508181017/7060961
本節引言: 本節給大家帶了的是ViewFlipper,它是Android自帶的一個多頁面管理控件,且可以自動播放! 和ViewPager不同,ViewPage
一、什麼是activityActivity 是用戶接口程序,原則上它會提供給用戶一個交互式的接口功能。它是 android 應用程序的基本功能單元。Activity 本身
項目地址:XBanner簡介:功能強大的圖片無限自動輪播控件,可支持自定義狀態點及指示器顯示位置等功能支持圖片無限輪播的控件,可進行自定義功能。主要功能:支持根據服務端返
本文實例講述了Android編程實現仿美團或淘寶的多級分類菜單效果。分享給大家供大家參考,具體如下:這裡要實現的是諸如美團/淘寶/百度糯米 多級分類菜單效果。當分類數量非