开发学院手机开发Android 开发 Android 操练:Gtalk(显示好友列表) 阅读

Android 操练:Gtalk(显示好友列表)

 2010-04-12 15:54:00 来源:WEB开发网   
核心提示:String name=cursor.getString(NICKNAME);String jid=cursor.getString(USERNAME);if(presence>0) layout.addView(row(new Contact(name,jid,presence)));cursor.next()

String name=cursor.getString(NICKNAME);

String jid=cursor.getString(USERNAME);

if(presence>0) layout.addView(row(new Contact(name,jid,presence)));

cursor.next();

}

}

class Contact

{ String name;

String jid;

int icon;

TextView text=null; // TODO: TEST

Contact(int i) // TEST

{ name="My Buddy "+i;

jid="Buddy"+i+"@jabber.net";

icon=R.drawable.icon;

}

Contact(String name,String jid,int presence)

{ this.name=" ("+presence+") "+name;

this.jid=jid;

switch(presence)

{

case Im.Presence.OFFLINE: icon=R.drawable.icon; break;

case Im.Presence.INVISIBLE: icon=R.drawable.icon; break;

case Im.Presence.DO_NOT_DISTURB: icon=R.drawable.icon; break;

case Im.Presence.AWAY: icon=R.drawable.icon; break;

case Im.Presence.IDLE: icon=R.drawable.icon; break;

case Im.Presence.AVAILABLE: icon=R.drawable.icon; break;

}

}

}

private TableRow row(final Contact contact)

{

TableRow template=(TableRow)findViewById(R.id.contacts_row_layout);

android.view.ViewGroup.LayoutParams layoutParams=template.getLayoutParams();

TableRow layout=new TableRow(this);

layout.setLayoutParams(layoutParams);

ImageView imageView=new ImageView(this);

imageView.setImageResource(contact.icon);

imageView.setPadding(2,6,2,0); // left, top, right, bottom

layout.addView(imageView);//,layoutParams);

final TextView text=new TextView(this);

text.setTag(contact); contact.text=text;

text.setText(contact.name);

text.setTypeface(Typeface.DEFAULT_BOLD);

text.setFocusable(true);

text.setOnClickListener(textClickListener);

layout.addView(text);//,layoutParams);

return(layout);

}

private OnClickListener textClickListener=new OnClickListener()

{ public void onClick(View view)

{ Contact contact=(Contact)view.getTag();

if(DEBUG) Log.d(TAG,"row: onClick: contactName="+contact.name);

}

};

}

上一页  1 2 

Tags:Android 操练 Gtalk

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接