bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

Android中使用ListView模擬微信好友功能

效果圖:

讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:申請域名、雅安服務(wù)器托管、營銷軟件、網(wǎng)站建設(shè)、德宏州網(wǎng)站維護、網(wǎng)站推廣。

Android中使用ListView模擬微信好友功能Android中使用ListView模擬微信好友功能

分析:

Android中使用ListView模擬微信好友功能

1、創(chuàng)建listView

2、創(chuàng)建數(shù)據(jù)

3、創(chuàng)建適配器

將數(shù)據(jù)放到呈現(xiàn)數(shù)據(jù)的容器里面。

將這個容器(帶數(shù)據(jù))連接適配器。

其實是直接在我們自己寫的adapter的getView重載方法中返回連接的view?!?/p>

 View view=View.inflate(mContext, com.example.weChatFriends.R.layout.item_friend, null);
    return view;

4、ListView設(shè)置適配器

代碼:

package fry;
import java.util.ArrayList;
import java.util.List;
import com.example.weChatFriends.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class Activity01 extends Activity implements OnItemSelectedListener,OnItemClickListener{
  private FriendModel friend;
  private ListView listView;
  private List<FriendModel> list;
  private weChatListAdapter adapter;
  //存資源圖片ID
  private int[] imageID=new int[]{R.drawable.image1,R.drawable.image2,
      R.drawable.image3,R.drawable.image4,R.drawable.image5,R.drawable.image6,
      R.drawable.image7,R.drawable.image8,R.drawable.image9,R.drawable.image10,
      R.drawable.image11};
  //存昵稱
  private String[] nickName=new String[]{"張三","吳京","戰(zhàn)狼","神煩xp","木魚"
      ,"水心","系大大","電影","血怒","創(chuàng)奇","講故事"
  };
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity01);
    init();
    setData();
  }
  private void setData() {
    //這里要是寫成for(int i:imageID),那么i就是資源id,例如2130837505
    for(int i=0;i<imageID.length;i++){
      FriendModel friend1=new FriendModel();
      //System.out.println(i);
      friend1.setImageNum(imageID[i]);
      friend1.setNickName(nickName[i]);
      friend1.setSignature("我要做比海賊王還強大的人");
      list.add(friend1);
    }
    adapter=new weChatListAdapter(list, this);
    listView.setAdapter(adapter);
  }
  private void init() {
    listView=(ListView) findViewById(R.id.listView);
    listView.setOnItemSelectedListener(this);
    listView.setOnItemClickListener(this);
    friend=new FriendModel();
    list=new ArrayList<FriendModel>();
  }
  /*
   * Callback method to be invoked when an item in this view has been selected. This callback is invoked only when the newly selected position is different from the previously selected position or if there was no selected item.(non-Javadoc)
   * @see android.widget.AdapterView.OnItemSelectedListener#onItemSelected(android.widget.AdapterView, android.view.View, int, long)
   */
  @Override
  public void onItemSelected(AdapterView<?> parent, View view, int position,
      long id) {
  }
  @Override
  public void onNothingSelected(AdapterView<?> parent) {
    // TODO Auto-generated method stub
  }
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position,
      long id) {
    FriendModel friendItem=(FriendModel) parent.getItemAtPosition(position);
    String s=friendItem.getNickName();
    Log.d("onItemClick","s");
    Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
  }
}
package fry;
import java.util.List;
import com.example.weChatFriends.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class weChatListAdapter extends BaseAdapter{
  private List<FriendModel> myData;
  private Context mContext;
  private ImageView avator;
  private TextView nickName1;
  private TextView signature1;
  private FriendModel friend;
  public weChatListAdapter(List<FriendModel> data, Context mContext) {
    super();
    this.myData = data;
    this.mContext = mContext;
  }
  //How many items are in the data set represented by this Adapter.
  @Override
  public int getCount() {
    // TODO Auto-generated method stub
    return this.myData.size();
  }
  //Get the data item associated with the specified position in the data set.
  @Override
  public Object getItem(int position) {
    // TODO Auto-generated method stub
    return this.myData.get(position);
  }
  //Get the row id associated with the specified position in the list.
  @Override
  public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
  }
  //Get a View that displays the data at the specified position in the data set. 
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View view=View.inflate(mContext, com.example.weChatFriends.R.layout.item_friend, null);
    //System.out.println(position);
    friend=myData.get(position);
    int ImageID=friend.getImageNum();
    String nickName=friend.getNickName();
    String signature=friend.getSignature();
    avator=(ImageView) view.findViewById(R.id.iv_avator);
    nickName1=(TextView)view.findViewById(R.id.tv_nickname);
    signature1=(TextView)view.findViewById(R.id.tv_signature);
    avator.setImageResource(ImageID);
    nickName1.setText(nickName);
    signature1.setText(signature);
    return view;
  }
}

自己創(chuàng)建的適配器

package fry;
public class FriendModel {
  //頭像的圖片id
  private int imageNum;
  //昵稱
  private String nickName;
  //個性簽名
  private String signature;
  public int getImageNum() {
    return imageNum;
  }
  public void setImageNum(int imageNum) {
    this.imageNum = imageNum;
  }
  public String getNickName() {
    return this.nickName;
  }
  public void setNickName(String nickName) {
    this.nickName = nickName;
  }
  public String getSignature() {
    return signature;
  }
  public void setSignature(String signature) {
    this.signature = signature;
  }
}

列表中聯(lián)系人數(shù)據(jù)的封裝

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/listView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" >
</ListView>
ListView
 ListView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" >
  <ImageView 
    android:id="@+id/iv_avator"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:src="@drawable/image1"
    />
  <TextView 
    android:id="@+id/tv_nickname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/iv_avator"
    android:layout_centerVertical="true"
    android:layout_marginLeft="20dp"
    android:text="張三"
    />
  <TextView 
    android:id="@+id/tv_signature"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:text="我要做比海賊王更強大的男人"
    />
</RelativeLayout>

用于存放數(shù)據(jù)的容器

文章名稱:Android中使用ListView模擬微信好友功能
URL地址:http://vcdvsql.cn/article16/pdeddg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、域名注冊、定制網(wǎng)站、定制開發(fā)、網(wǎng)站收錄靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設(shè)