Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android如果用ListView做一個表格形式

android如果用ListView做一個表格形式

編輯:關於Android編程

效果圖:

\

 

這樣來寫:

 

@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test);
		ListView list = (ListView)findViewById(R.id.lvLinks);
		SquareItemAdapter adapter = new SquareItemAdapter(this);
		list.setDivider(null);
		list.setAdapter(adapter);
		
	}
	
	
	private class SquareItemAdapter extends BaseAdapter {
		Context context;
		TextView tvName;

		public int getCount() {
			// TODO Auto-generated method stub
			return 3;
		}

		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			final LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			final View v = inflater.inflate(R.layout.square_item_view, null);
			tvName = (TextView) v.findViewById(R.id.tvItemName);
			if (position == 0) {
				tvName.setText(getString(R.string.link_lookaround));
				v.setBackgroundResource(R.drawable.circle_list_top);
			}
			else if (position == 1) {
				tvName.setText(getString(R.string.link_recommend));
				v.setBackgroundResource(R.drawable.circle_list_middle);
			}
			else {
				tvName.setText(getString(R.string.link_hot));
				v.setBackgroundResource(R.drawable.circle_list_bottom);
			}

			return v;
		}

		public SquareItemAdapter(Context ct) {
			context = ct;

		}
	}



	
	
		
	
		



如果做一下效果的圖:

\

 

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved