由于整个项目比较大,而且涉及面很广,只好截取一小部分代码
单击ListView的某一项的响应事件,定义了View的成员变量mTempView来获取点击的单一TextView,某一行的TextView实例
final String items[]=new String []{"帅哥","美女","保密"};
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
switch(arg2){
case 0:
mTempView =arg1;
showDialog(Globals.DIALOG_MYINFO_GENDER);
break;
case 1:
mTempView =arg1;
showDialog(Globals.DIALOG_MYINFO_BIRTHDAY);
break;
case 2:
mTempView =arg1;
showDialog(Globals.DIALOG_MYINFO_SIGNATURE);
break;
}
}
弹出的dialog:进行相关设置
case Globals.DIALOG_MYINFO_GENDER:{
final String items[]=new String []{"帅哥","美女","保密"};
return new AlertDialog.Builder(this).
setTitle(R.string.personal_profile_gender)
.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
//R.array.person_profile_geder_array
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
// setTitle(items[which]);
PersonalProfileActivity.this.setmTempId(which);
}
}).setPositiveButton("确定",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
setGender(mTempId);
removeDialog(Globals.DIALOG_MYINFO_GENDER);
}
}).setNegativeButton("取消",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
removeDialog(Globals.DIALOG_MYINFO_GENDER);
}
}).create();
}
动态更新TextView上的文本
public void setGender(int gender){
TextView currView=(TextView)mTempView.findViewById(R.id.personal_profile_listitem_body);
switch(gender){
case 0:
currView.setText("帅哥");
break;
case 1:
currView.setText("美女");
break;
case 2:
currView.setText("保密");
break;
}
}