2014-09-08 2 views
3
private void showPopup(final Activity context, Point p) { 
     int popupWidth = 800; 
     int popupHeight = 1100; 

     // Inflate the popup_layout.xml 
     LinearLayout viewGroup = (LinearLayout) context 
       .findViewById(R.id.popup); 
     LayoutInflater layoutInflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View layout = layoutInflater.inflate(R.layout.notifcationpopup_layout, 
       viewGroup); 
     popup = new PopupWindow(context); 
     popup.setContentView(layout); 
     popup.setWidth(popupWidth); 
     popup.setHeight(popupHeight); 
     popup.setFocusable(true); 

     // Some offset to align the popup a bit to the right, and a bit down, 
     // relative to button's position. 
     int OFFSET_X = 100; 
     int OFFSET_Y = 40; 

     // Clear the default translucent background 
     popup.setBackgroundDrawable(new BitmapDrawable()); 

     // Displaying the popup at the specified location, + offsets. 
     popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y 
       + OFFSET_Y); 

     rowItems = new ArrayList<RowItem>(); 
     // for (int i = 0; i < titles.length; i++) { 
     // RowItem item = new RowItem(titles[i], descriptions[i]); 
     // rowItems.add(item); 
     // } 
     dbManager1 = new DataBaseManager(context); 
     notifies = dbManager1.getNotificationList(); 
     System.out.println("today " + notifies.size()); 
     for (int i = 0; i < notifies.size(); i++) { 
      System.out 
        .println("Valueeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee:" 
          + notifies.get(i).getNotificationDescrpiton() 
          + "\n" 
          + notifies.get(i).getNotificationServerId() 
          + "\n" + notifies.get(i).getNotificationDatetime()); 

     } 
     listView = (ListView) layout.findViewById(R.id.listView1); 
     Notifcationadapter adapter = new Notifcationadapter(this, notifies); 
     listView.setAdapter(adapter); 
     listView.setOnItemClickListener(this); 

    } 

    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, 
      long id) { 
     // TODO Auto-generated method stub 

     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(); 

     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")) { 
      // i = new Intent(context, PostActivity.class); 

      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")) { 

      displayView(0); 

      // ((FragHome) fragment).showMap(); 

      popup.dismiss(); 

      Toast.makeText(this, "Post", 1000).show(); 

     } 

    } 

Это мой код HOmeActivity для всплывающего окна.Как применить условие для выбора элемента списка Listview в android

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

    // 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; 
     ImageView yesimage; 

     ImageView 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, null); 
      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 = (ImageView) convertView 
        .findViewById(R.id.imageView1); 
      holder.noimage = (ImageView) 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(); 

     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) { 
        // TODO Auto-generated method stub 
        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); 
        Toast.makeText(context, "Yes", 10000).show(); 

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

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        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); 
        Toast.makeText(context, "NO", 10000).show(); 
        // holder.linear2.setVisibility(View.INVISIBLE); 
        holder.yesimage.setVisibility(View.GONE); 
        holder.noimage.setVisibility(View.GONE); 
        holder.rejected.setVisibility(View.VISIBLE); 
       } 
      }); 

     } 

     else { 

      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); 
      holder.yesimage.setVisibility(View.GONE); 
      holder.noimage.setVisibility(View.GONE); 
     } 

     if (position % 2 == 0) { 

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

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

     } 

     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; 
    } 

} 

Это мой адаптер класс для списка ракурса есть одна кнопки ДА или НЕТ в каждом элементе списка просмотра, когда просмотр списка печати. я хочу, когда мы нажмем на кнопку Да, тогда только itemclik должен работать. Я имею в виду один элемент. Я должен перейти в другое действие, если мы нажмем «Нет кнопки», тогда он не должен работать. Элемент щелчка мышью на элементе списка. Я не должен переходить к другому действию.

Ниже приведен список видов экрана: enter image description here

+0

на вашем держателе.yesimage onclicklistener назовите ваше намерение следующим образом. Intent i = new Intern (context, youractivity.class); startActivity (i); надеюсь, это поможет вам. – Nathiya

+0

но у меня есть применить в HOmeActvity пункт класса функции мыши – Edge

+0

и я не в состоянии вызвать в классе адаптера \t \t \t \t \t \t Intent I = новый Intent (контекст, RoutePathActivity.class); \t \t \t \t \t startActivity (i); – Edge

ответ

0

Пожалуйста, проверьте, что я отредактировал ваш код. yesimage - это ваша кнопка с тиковым изображением справа. В обновлении класса Notifcationadapter приведен код ниже.

 holder.yesimage.setOnClickListener(new OnItemClickListener(position)); 

     private class OnItemClickListener implements OnClickListener{   
      private int mPosition;   
      OnItemClickListener(int position){ 
        mPosition = position; 
      }   
      @Override 
      public void onClick(View arg0) {  
       context.onItemtickClick(mPosition);   
      }    
    } 

В вашей домашней деятельности Добавьте нижеприведенный код для onItemtickClick.

 public void onItemtickClick(int mPosition) { 
     // TODO Auto-generated method stub 
      Intent i = new Intent(HomeActivity.this,RoutePathActivity.class);  
      i.putExtra("lat", Latreccvier); 
      i.putExtra("lon", Lonreccvier); 
      startActivity(i); 
     } 
+0

, но как насчет функции onitemclcik, которую я применил к классу Actvity, я использовал код ur, но исключение приходит nullPointer Exception @Nathiya – Edge

+0

даже мне нужно передать значение другому классу Intent i = new Intent (это, RoutePathActivity.class); i.putExtra ("lat", Latreccvier); i.putExtra ("lon", Lonreccvier); startActivity (i); как этот – Edge

+0

u нужен весь элемент списка щелчка или адаптер. в ur post u объяснили, что, щелкнув по галочку, у него будет другое действие. в то время как щелчок x-изображения ничего не сделает, это функциональность, и вам нужно получить результат. Я прав. – Nathiya

Смежные вопросы