1
@Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {

        String notifcationtype = notifies.get(position).getNotificationType();
        String nOtifcationMessge = notifies.get(position)
                .getNotificationDescrpiton();
        String notifcationdatetime = notifies.get(position)
                .getNotificationDatetime();

        String NotifcationSenderid = notifies.get(position)
                .getNotificationSenderID();
        String NotifcationRecciverid = notifies.get(position)
                .getNotificationRecieverID();
        int Notifcationid = Integer.parseInt(notifies.get(position)
                .getNotificationId());

        String NOtifcationstatus = notifies.get(position)
                .getNotificationStatus();

        final int positionRow = listView.getPositionForView((View) view
                .getParent());

        String Latreccvier = "";
        String Lonreccvier = "";
        Cursor cursor = dbManager1.fetchContactInfo(NotifcationRecciverid);
        if (cursor != null && cursor.moveToFirst()) {

            Latreccvier = cursor.getString(cursor

            .getColumnIndex(DataProviderConstants.CONTACT_LAT_COLUMN));

            Lonreccvier = cursor.getString(cursor

            .getColumnIndex(DataProviderConstants.CONTACT_LON_COLUMN));

            cursor.close();

        }

        Log.e("Reccvierid", NotifcationRecciverid);
        Log.e("Reccvierid", Latreccvier);
        Log.e("Reccvierid", Lonreccvier);

        // Intent i = null;
        if (notifcationtype.equals("1")) {
            dbManager1.updateNotification(NotifcationSenderid, "true");
            Intent i = new Intent(this, RoutePathActivity.class);
            i.putExtra("lat", Latreccvier);
            i.putExtra("lon", Lonreccvier);
            startActivity(i);
            Toast.makeText(this, "Request", 1000).show();

        } else if (notifcationtype.equals("2")) {
            dbManager1.updateNotification(NotifcationSenderid, "4");
            displayView(0);

            ((FragHome) fragment).showMap();
            Log.e("", "Showmap");
            Bundle args = new Bundle();
            // args.putString("CID", "2");
            popup.dismiss();

        } else if(NotifcationSenderid.equals("3")) {
            Toast.makeText(this, "You Have Rejected ", 1000).show();
        }
    }

这是 onItemClick 函数,我可以在数据库中单击项目时插入值。使用这行代码,我可以更新数据库中的值。 dbManager1.updateNotification(NotifcationSenderid, "4");

public class Notifcationadapter extends BaseAdapter {
    private static ArrayList<Notify> values;
    Context context;
    String senderid;
    String imagepath;
    String member_id;
    String recevr_id;
    String jsonResp;

    // List<RowItem> rowItems;
    ViewHolder holder = null;

    LinearLayout linear2;

    DataBaseManager dbManager = new DataBaseManager(context);
    ArrayList<Notify> notifies;

    public Notifcationadapter(Context context, ArrayList<Notify> notifies) {
        super();
        this.context = context;
        this.notifies = notifies;

    }

    /* private view holder class */
    private class ViewHolder {

        TextView txtTitle;
        TextView txtDesc;
        Button yesimage;

        Button noimage;
        TextView revresetime;

        TextView rejected;
        ImageView notificationuserimage;
        LinearLayout linear2;

    }

    public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater mInflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.notifcationlistitem,
                    parent, false);
            holder = new ViewHolder();
            // holder.linear2 = (LinearLayout) convertView
            // .findViewById(R.id.linear2);
            holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);

            holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
            holder.yesimage = (Button) convertView
                    .findViewById(R.id.imageView1);
            holder.noimage = (Button) convertView.findViewById(R.id.imageView2);
            holder.revresetime = (TextView) convertView
                    .findViewById(R.id.revresetime);
            holder.rejected = (TextView) convertView
                    .findViewById(R.id.rejectedrequest);
            holder.notificationuserimage = (ImageView) convertView
                    .findViewById(R.id.notificationuserimage);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        // holder.txtTitle.setText("Title");
        String statustype = notifies.get(position).getNotificationType();
        final String NotifcationSenderid = notifies.get(position)
                .getNotificationSenderID();

        if (statustype.equals("1")) {

            holder.txtDesc.setText(notifies.get(position)
                    .getNotificationDescrpiton());

            holder.revresetime.setText(Functions
                    .setLastSeenNotifcationTime(notifies.get(position)
                            .getNotificationDatetime()));
            holder.txtTitle.setText("Request For travelling");

            senderid = notifies.get(position).getNotificationSenderID();
            imagepath = "http://api.lociiapp.com/TransientStorage/"

            + senderid + ".jpg";
            AQuery aq = new AQuery(context);

            aq.id(holder.notificationuserimage).image(imagepath);

            holder.yesimage.setVisibility(View.VISIBLE);
            holder.noimage.setVisibility(View.VISIBLE);

            holder.yesimage.setTag(convertView);
            holder.yesimage.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    View parentView = (View) arg0.getTag();
                    View view = parentView.findViewById(R.id.imageView1);
                    view.setVisibility(View.GONE);
                    view = parentView.findViewById(R.id.imageView2);
                    view.setVisibility(View.GONE);
                    // view = parentView.findViewById(R.id.linear2);
                    view.setVisibility(View.INVISIBLE);
                    view = parentView.findViewById(R.id.runnimage);
                    view.setVisibility(View.INVISIBLE);
                    new sendMesgTask().execute("Acepted");
                    Toast.makeText(context, "Yes", 10000).show();

                }
            });
            holder.noimage.setTag(convertView);
            holder.noimage.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    View parentView = (View) v.getTag();
                    View view = parentView.findViewById(R.id.imageView1);
                    view.setVisibility(View.GONE);
                    view = parentView.findViewById(R.id.imageView2);
                    view.setVisibility(View.GONE);
                    view = parentView.findViewById(R.id.rejectedrequest);
                    view.setVisibility(View.VISIBLE);

                    dbManager
                            .typeusupdateNotification(NotifcationSenderid, "4");
                    holder.yesimage.setVisibility(View.GONE);
                    holder.noimage.setVisibility(View.GONE);
                    holder.rejected.setVisibility(View.VISIBLE);
                }
            });

        }

        else if (statustype.equals("2")) {

            holder.txtDesc.setText(notifies.get(position)
                    .getNotificationDescrpiton());
            holder.txtTitle.setText("Post");
            holder.revresetime.setText(Functions
                    .setLastSeenNotifcationTime(notifies.get(position)
                            .getNotificationDatetime()));

            senderid = notifies.get(position).getNotificationSenderID();
            imagepath = "http://api.lociiapp.com/TransientStorage/"

            + senderid + ".jpg";
            AQuery aq = new AQuery(context);
            aq.id(holder.notificationuserimage).image(imagepath);

            holder.yesimage.setVisibility(View.GONE);
            holder.noimage.setVisibility(View.GONE);
        }

        else if (statustype.equals("4"))

        {
            holder.txtTitle.setText("Value 4 ");
        }

        else {
            holder.txtDesc.setText(notifies.get(position)
                    .getNotificationDescrpiton());
            holder.txtTitle.setText("Accept/ Reject ");
            holder.txtDesc.setTextColor(Color.RED);
            holder.yesimage.setVisibility(View.GONE);
            holder.noimage.setVisibility(View.GONE);
            holder.revresetime.setText(Functions
                    .setLastSeenNotifcationTime(notifies.get(position)
                            .getNotificationDatetime()));
            senderid = notifies.get(position).getNotificationSenderID();
            imagepath = "http://api.lociiapp.com/TransientStorage/" + senderid
                    + ".jpg";
            AQuery aq = new AQuery(context);
            aq.id(holder.notificationuserimage).image(imagepath);

        }
        String notifcationsenderid = notifies.get(position)
                .getNotificationSenderID();
        String notisread = notifies.get(position).getNotificationStatus();
        if (notisread.equals("false")) {

            convertView.setBackgroundColor(Color.parseColor("#f5f6f1"));
        } else {
            convertView.setBackgroundColor(Color.parseColor("#ffffff"));
        }

        return convertView;
    }

    @Override
    public int getCount() {
        return notifies.size();
    }

    @Override
    public Object getItem(int position) {
        return notifies.get(position).getNotificationType();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

但我想要是或没有按钮我想要在该按钮单击中更新值,但我无法做到没有更新:

public int typeusupdateNotification(String notificationid, String type) {
        int result = 0;
        ContentValues values = new ContentValues();
        values.put(DataProviderConstants.NOTIFY_SENDER_ID, notificationid);
        values.put(DataProviderConstants.NOTIFY_TYPE,type );

        result = mContext.getContentResolver().update(
                DataProviderConstants.NOTIFICATION_TABLE_CONTENTURI, values,
                DataProviderConstants.NOTIFY_SENDER_ID + "=?",
                new String[] { notificationid });

        return result;
    }

此数据库功能在项目上单击其工作正常但是当我尝试使用 Ad-pater 更新是或否按钮但我无法更新时我调试然后result =mContext值变为终止请建议哪里做错了。

4

0 回答 0