0
我有一個自定義列表視圖有兩個textviews和圖像視圖。點擊顯示自定義對話框的每行iam。打開列表視圖後,單擊行iam可以查看對話框,而如果我滾動並單擊行對話框不顯示。onListItemClick無法正常工作,如果圖像加載
我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();
}
我觀察到的另一件事是,如果它是一個TextView(而不是ImageView的),即使如果我滾動亞姆能夠爲每行顯示的對話框。
我的適配器方法
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" />
您需要發佈所有列表代碼,因爲它似乎問題與您的列表,而不是您的對話框。 – Barak
您的listitem點擊在哪裏? – kyogs
發佈適配器方法和xml。其實如果我用列表項目替換圖像視圖,然後IAM沒有得到任何問題。並與圖像視圖列表顯示正確。只有在滾動iam後才能獲得對話。 – user1203673