按钮点击不在列表视图中工作

问题描述:

我的XML是 -按钮点击不在列表视图中工作

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/llMainLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:padding="10dp" > 

<TextView 
    android:id="@+id/txtContentTitle" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="1dp" 
    android:layout_marginTop="2dp" 
    android:gravity="left" 
    android:maxLines="2" 
    android:text="test" 
    android:textColor="#000000" 
    android:textSize="15dp" 
    android:textStyle="normal" /> 

<TextView 
    android:id="@+id/txtContent" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="2dp" 
    android:layout_marginTop="2dp" 
    android:gravity="left" 
    android:text="test" 
    android:textColor="#000000" 
    android:textStyle="bold" /> 

<ProgressBar 
    android:id="@+id/downloadProgressBar" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="60dp" 
    android:layout_height="5dp" 
    android:max="@integer/downloadProgressMax" 
    android:visibility="gone" /> 

<Button 
    android:id="@+id/btn_notificationContent_download" 
    android:layout_width="wrap_content" 
    android:layout_height="19dp" 
    android:layout_gravity="left" 
    android:layout_marginLeft="0dp" 
    android:layout_marginTop="2dp" 
    android:background="@android:color/transparent" 
    android:clickable="true" 
    android:gravity="left|center_vertical|center_horizontal" 
    android:paddingLeft="0dp" 
    android:text="Download" 
    android:textColor="#ffff1205" 
    android:textSize="13dp" 
    android:textStyle="normal" /> 

和我的适配器类是 -

@Override 
public View getView(final int position, View convertView,ViewGroup parent){ 
    try { 
     if (convertView == null) { 
      LayoutInflater inflator = (LayoutInflater) context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = inflator.inflate(
        R.layout.notification_listview_item, null); 

      // convertView = 
      // inflater.inflate(R.layout.notification_listview_item, 
      // parent, false); 

     } 
     TextView txtContent = (TextView) convertView 
       .findViewById(R.id.txtContent); 
     txtContent.setTag(position); 
     TextView txtContentTitle = (TextView) convertView 
       .findViewById(R.id.txtContentTitle); 
     Button btn_notificationContent_download = (Button) convertView 
       .findViewById(R.id.btn_notificationContent_download); 
     ProgressBar downloadProgressBar = (ProgressBar) convertView 
       .findViewById(R.id.downloadProgressBar); 
     if (isDownloading && (download != null)) { 
      downloadProgressBar.setVisibility(View.VISIBLE); 
      downloadProgressBar.setProgress(download.getProgress()); 
      downloadProgressBar.invalidate(); 
     } else { 
      downloadProgressBar.setVisibility(View.GONE); 
     } 
     JSONObject obj = null; 
     try { 
      obj = AppService.getAppService().getLanguageJsonObject(); 
     } catch (NullPointerException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (Exception e) { 
      // TODO: handle exception 
     } 
     if (strVersion.contentEquals("0")) { 
      String msg = null; 
      if (obj != null) { 
       try { 
        msg = obj.getString(LanguageTags.TAG_DOWNLOAD); 
       } catch (JSONException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 
      if (msg.equalsIgnoreCase("") || msg == null) { 
       msg = "Download"; 
      } 
      btn_notificationContent_download.setText(msg); 
     } else { 
      String msg = null; 
      if (obj != null) { 
       try { 
        msg = obj.getString(LanguageTags.TAG_UPDATE); 
       } catch (JSONException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 
      if (msg.equalsIgnoreCase("") || msg == null) { 
       msg = "Update"; 
      } 
      btn_notificationContent_download.setText(msg); 
     } 
     txtContent.setTag(position); 
     btn_notificationContent_download.setTag(position); 
     btn_notificationContent_download 
       .setOnClickListener(new OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         // TODO Auto-generated method stub 
         mPosition = (Integer) v.getTag(); 

         UrlBuilder builder = AppService.getAppService() 
           .getUrlBuilder(); 
         String filePath = builder 
         String contentId = Content 
           .getContentId(notificationList 
             .get(mPosition)); 
         if (contentId == null) { 
          contentId = Content.getId(notificationList 
            .get(mPosition)); 
         } 
        } 
       }); 
     convertView.setTag(notificationList.get(position)); 
     convertView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(AppService.getAppService() 
         .getApplicationContext(), abc.class); 
       intent.putExtra(AppKeys.KEY_JSON_CONTENT, 
         ((JSONObject) v.getTag()).toString()); 
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       AppService.getAppService().getApplicationContext() 
         .startActivity(intent); 
      } 
     }); 
    } catch (Exception e) { 
    } 
    return convertView; 
} 

我的按钮,点击convertview听众不工作。不知道我在哪里错了。它以前工作,但现在它只是卡住了。有什么我失踪?

由于提前

+0

这行添加到您的项目布局的android:descendantFocusability = “blocksDescendants” –

+0

似乎复制http://*.com/questions/6703390/listview-setonitemclicklistener-not-working-by-adding-button –

请把这个按钮布局

android:focusable="false" 
android:focusableInTouchMode="false" 
+0

这不提供问题的答案。要批评或要求作者澄清,请在其帖子下方留言。 –

+1

好@MuhammedRefaat我会在将来保重。感谢您支持 –

+0

感谢您的理解,这里的重点是SO中的人必须获得知识并学习他们所做的每一篇文章,因此只解决问题而不作任何澄清不会只是提供一点点声明,他为什么要这样做会很好。谢谢 :) –