2011-09-01 4 views
0

하나의 클릭 할 수있는 이미지가있는 목록보기를 구현하려고합니다. 각 행에서보기,이 사용자 지정 어댑터를 만든 모든 메서드를 재정의하십시오. 이제 내 문제는 그 난이 제대로 작동하지 않는 것을 행을 클릭하지 않고 이미지보기를 클릭하면 내 코드는 아래이미지 목록보기에서 제대로 작동하는 Viewnot

보호 무효 onListItemClick (ListView에 리터,보기 V, 최종 INT 위치, 긴 ID) {

super.onListItemClick(l, v, position, id); 

    RowData rowObject = (RowData) l.getItemAtPosition(position); 
    contactId= rowObject.getTextId(); 

//contactId gives the position of the row clicked in the list view. 

    Log.e("on item clicked", contactId.toString()); 

    ImageView nextView = rowObject.getImageobject(); 
    nextView.setClickable(true); 
    nextView.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
       // TODO Auto-generated method stub 
      Log.i("Value of row id", String.valueOf(position)); 
       Intent myintent = new Intent(v.getContext(),Info.class); 
       myintent.putExtra("ContactId", contactId); 
       v.getContext().startActivity(myintent); 

     } 
    }); 

여기에서 행을 먼저 클릭 한 다음 이미지보기를 클릭하면 문제가 없습니다. 그러나 행을 클릭하지 않고 이미지보기를 클릭하면 (즉, 행을 선택하지 않고) 마지막 클릭 한 행의 위치를 ​​차지합니다.

도와주세요.

답변

0

확인 마지막으로 목록보기에 너무 파고 난 자신에 의해 솔루션을 가지고, 그리고 내가 이미지가 (INT보기 클릭 할 때마다 지금, 사용자 정의 어댑터의 getView 방법을 혈통 position) getview의 인수는 clicked.here에있는 행의 위치를 ​​알려주고 나중에 구현 한 코드입니다.

private class CustomAdapter extends ArrayAdapter<RowData> { 
    public CustomAdapter(Context context,int resource,int textViewResourceId,List<RowData> objects) { 
     super(context, resource, textViewResourceId, objects); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ViewHolder holder = null; 
     TextView Name  = null; 
     TextView JobTitle = null; 
     ImageView Emailimage = null; 
     ImageView Phoneimage = null; 
     ImageView nextView = null; 
     RowData rowData = getItem(position); 

     if(null == convertView){ 
      mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = mInflater.inflate(R.layout.contact_found_list_item_row, null); 
      holder = new ViewHolder(convertView); 
      convertView.setTag(holder); 
     } 

     String positionId = String.valueOf(position); 
     holder = (ViewHolder) convertView.getTag(); 
     Name = holder.gettitle(); 
     Name.setText(rowData.mTitle); 
     JobTitle = holder.getdetail(); 
     JobTitle.setText(rowData.mDetail);              
     Emailimage=holder.getImage(); 
     Emailimage.setImageResource(rowData.phoneId); 
     Phoneimage = holder.getphoneImage(); 
     Phoneimage.setImageResource(rowData.emailId); 
     nextView = holder.getNextViewObject(); 
     nextView.setTag(positionId); 
     nextView.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       ImageView iv = (ImageView)v; 
       String rowid = (String)iv.getTag(); 
       Intent myintent = new Intent(v.getContext(),Info.class); 
       myintent.putExtra("ContactId", rowid); 
       v.getContext().startActivity(myintent); 
      } 
     }); 

     return convertView; 
    } 

    private class ViewHolder { 
     private View mRow; 

     private TextView Name = null; 
     private TextView JobTitle = null; 
     private ImageView Emaillogo = null; 
     private ImageView phonelogo = null; 
     private ImageView nextViewlogo = null; 

     public ViewHolder(View row) { 
      mRow = row; 
     } 

     public TextView gettitle() { 
      if(null == Name){ 
       Name = (TextView) mRow.findViewById(R.id.txtfirstname); 
      } 
      return Name; 
     }  

     public TextView getdetail() { 
      if(null == JobTitle){ 
       JobTitle = (TextView) mRow.findViewById(R.id.txtjobtitle); 
      } 
      return JobTitle; 
     } 

     public ImageView getImage() { 
      if(null == Emaillogo){ 
       Emaillogo = (ImageView) mRow.findViewById(R.id.emaillogo); 
      } 
      return Emaillogo; 
     } 
     public ImageView getphoneImage(){ 
      if(null == phonelogo){ 
       phonelogo = (ImageView) mRow.findViewById(R.id.mobilelogo); 
      }return phonelogo; 
     } 
     public ImageView getNextViewObject(){ 
      if(null == nextViewlogo){ 
       nextViewlogo = (ImageView)mRow.findViewById(R.id.nextbutton); 
      }return nextViewlogo; 
     } 

    } 
1

내 getView 기능을 참조하십시오. 그 목록에서 하나의 개체가 나타납니다. . . 버튼을 클릭하는 동안 클릭을 얻을 수 있습니다.

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

      View v = convertView; 
      if (v == null) 
      { 
       try 
       { 
       LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       v = vi.inflate(R.layout.pantry_list_row, null); 



        } 
       catch(Exception e) 
       { 
        System.out.println("Excption Caught"+e); 
       } 
      } 
      PantreisInfo p = items.get(position); 


      if (p != null) 
      { 
       TextView name = (TextView) v.findViewById(R.id.pantryName); 
       TextView add1= (TextView) v.findViewById(R.id.pantryAddress1); 
       TextView add2=(TextView)v.findViewById(R.id.pantryAddress2); 
       TextView phno = (TextView) v.findViewById(R.id.pantryPhno); 
       TextView distTime = (TextView) v.findViewById(R.id.distTime); 

//

   if (name != null) 
       { 
        name.setText(p.getName().get(0).toString()); 
       } 
       if (add1 != null) 
       { 
        add1.setText(p.getAddress1().get(0).toString()); 
       } 
       if (add2 != null) 
       { 
        add2.setText(p.getAddress2().get(0).toString()); 
       } 
       if (phno != null) 
       { 
        phno.setText(p.getPhone().get(0).toString()); 

       } 
       if (distTime!= null) 
       { 
        distTime.setText("Distribution Time: "+p.getDistTime().get(0).toString()); 
       } 
      } 
       ImageView phbtn=(ImageView)v.findViewById(R.id.phbtn); 
       phbtn.setOnClickListener(new View.OnClickListener() 
       { 

        @Override 
        public void onClick(View arg0) 
        { 

         final AlertDialog.Builder dialog=new AlertDialog.Builder(PantriesListActivity.this); 
         PantreisInfo p=items.get(position); 

         String tempPhone=p.getPhone().get(0).toString(); 
         String phoneNumber=""; 
         for(int i=0;i<tempPhone.length();i++) 
         { 
          if (Character.isDigit(tempPhone.charAt(i))) 
          { 
           System.out.println(tempPhone.charAt(i)); 
           phoneNumber=phoneNumber+tempPhone.charAt(i); 
          } 

         } 

         dialog.setMessage("Press ok to Dial "+phoneNumber+",otherwise click on cancel to discard."); 
         final String number="tel:" +phoneNumber.trim(); 

         dialog.setPositiveButton("Ok",new DialogInterface.OnClickListener() 
         { 

          @Override 
          public void onClick(DialogInterface arg0, int arg1) 
          { 
           // TODO Auto-generated method stub 

            Intent callIntent = new Intent(Intent.ACTION_CALL,Uri.parse(number)); 
            startActivity(callIntent); 

           dialog.setCancelable(true); 
          } 
         }); 
         dialog.setNegativeButton("Cancel",new DialogInterface.OnClickListener() { 

          @Override 
          public void onClick(DialogInterface dfdialog, int which) 
          { 
           // TODO Auto-generated method stub 
           dialog.setCancelable(true); 
          } 
         }); 

         dialog.show(); 
         //Toast.makeText(PantriesListActivity.this,""+p.getPhone().get(0), Toast.LENGTH_SHORT).show(); 



        } 
       }); 


       return v; 
     } 
+0

안녕하세요 explorer for yr help. 하지만 실제로 원하는 모든 행의 이미지보기를 클릭하면 전체 행을 클릭해야합니다 (그래서 내가 행의 위치를 ​​얻을 수있을 것이고 그 위치는 다음 활동으로 넘어갈 것입니다), 어떤 식 으로든 말할 수 있습니다. 해야 할 일 –

+1

ImageView 속성을 해제해야합니다. ImageView 속성을 android로 설정하면됩니다 : clickable = "false" –

관련 문제