我有一个带有两个文本视图和一个图像视图的自定义列表视图。单击每一行时,我会显示一个自定义对话框。打开列表视图并单击行后,我能够查看对话框,而如果我滚动并单击行,则不会显示对话框。
我的 onListItemclick 代码如下`
final Dialog password = new Dialog(VCStegoInboxWithOutCheckboxes.this);
password.setContentView(R.layout.dialog);
password.setTitle("Enter your Password");
final EditText getPassword = (EditText) password
.findViewById(R.id.edconfirmpwd);
Button okButton = (Button) password.findViewById(R.id.ok);
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String ConfirmCode = getPassword.getText().toString();
SharedPreferences settingsActivity = getSharedPreferences(
"UserName", Activity.MODE_PRIVATE);
String Password = settingsActivity.getString("Password", null);
if (ConfirmCode.equals(Password)) {
Intent showMsgIntent = new Intent();
showMsgIntent.setClass(getApplicationContext(),
VCStegoShowMessageScreen.class);
startActivity(showMsgIntent);
} else {
Toast.makeText(getBaseContext(), "InvalidPassword",
Toast.LENGTH_SHORT).show();
}
password.dismiss();
}
});
Button cancelButton = (Button) password.findViewById(R.id.cancel);
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("Entered on cancel button clicked");
password.dismiss();
}
});
password.show();
}
我观察到的另一件事是它是否是文本视图(而不是图像视图),即使我滚动 iam 能够为每一行显示对话框。
我的适配器方法是
public class InboxAdapter extends BaseAdapter {
private LayoutInflater inflater;
private TextView Tvname, TVtimeStamp;
private ImageView IVmsg;
public InboxAdapter(Context context, List<VCStegoInboxList> inboxList) {
inflater = LayoutInflater.from(context);
VCStegoInboxWithOutCheckboxes.Inboxlist = inboxList;
}
public class ViewHolder{
private TextView Tvname;
private TextView TVtimeStamp;
private ImageView IVmsg;
}
public int getCount() {
return VCStegoInboxWithOutCheckboxes.Inboxlist.size();
}
// @Override
public Object getItem(int position) {
return VCStegoInboxWithOutCheckboxes.Inboxlist.get(position);
}
// @Override
public long getItemId(int position) {
return position;
}
// @Override
public View getView(final int position, View convertView,
ViewGroup parent) {
ViewHolder holder;
if (convertView==null){
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.inboxtextviews, null);
Tvname = (TextView) convertView.findViewById(R.id.tvinboxname);
IVmsg = (ImageView) convertView.findViewById(R.id.tvinboxmsg);
TVtimeStamp = (TextView) convertView.findViewById(R.id.tvtimeStamp);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
Tvname.setText(VCStegoInboxWithOutCheckboxes.Inboxlist
.get(position).getname());
IVmsg.setImageBitmap(VCStegoInboxWithOutCheckboxes.Inboxlist.get(
position).getBitmap());
TVtimeStamp.setText(VCStegoInboxWithOutCheckboxes.Inboxlist.get(
position).getTimeStamp());
return convertView;
}
}
我的 xml 文件是
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/tvinboxname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/tvinboxmsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvinboxname"
android:contentDescription="@string/contentDes" />
<TextView
android:id="@+id/tvtimeStamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/tvinboxmsg"
android:textAppearance="?android:attr/textAppearanceSmall" />