亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

繼承BaseAdapter實現布局文件內容在手機屏幕上的顯示

標簽:
Android

5bbecab40001200603320503.jpg

1.activity_main.xml   设置listView

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >


    <ListView

        android:id="@+id/lv_01"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

         />


</RelativeLayout>

2.MainActivity.java

package com.example.day07_baseadapter;


import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;


import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ListView;

import android.widget.Toast;


public class MainActivity extends Activity {


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        ListView lv=(ListView) findViewById(R.id.lv_01);

        List<Map<String,Object>>data=new ArrayList<Map<String,Object>>();

        for(int i=0;i<20;i++){

         Map<String,Object>map=new HashMap<String, Object>();

         if(i%2==0){

         map.put("mv","美女"+i);

         map.put("mv_img",R.drawable.mv);

         }else{

         map.put("mv","帅哥"+i);

         map.put("mv_img",R.drawable.sg);

         }

         data.add(map);

        }

        MyAdapter adapter=new MyAdapter(MainActivity.this,data);

        lv.setAdapter(adapter);

        lv.setOnItemClickListener(new OnItemClickListener() {


@Override

public void onItemClick(AdapterView<?> arg0, View arg1, int 


arg2,

long arg3) {

// TODO Auto-generated method stub

Toast.makeText(MainActivity.this,"第"+arg2+"图


片!",0).show();

}

});

    }



   

    

}

3.item.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="horizontal" >

    <TextView 

        android:id="@+id/tv_01"

        android:layout_height="wrap_content"

        android:layout_width="0dp"

        android:layout_weight="1"

        android:gravity="center"

        android:textColor="#00ff00"

        />

    <ImageView 

        android:id="@+id/iv_01"

        android:layout_height="wrap_content"

        android:layout_width="0dp"

        android:layout_weight="1"

        android:maxWidth="80px"

        android:adjustViewBounds="true"

        />


</LinearLayout>

原文链接:http://www.apkbus.com/blog-813041-61100.html

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消