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

时间:2015-11-03 11:10:51

标签: android android-listview

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

我的按钮和转换视图点击监听器无法正常工作。不知道我错在哪里..以前工作但现在它只是卡住了。有什么我想念的吗?

先谢谢

1 个答案:

答案 0 :(得分:0)

请把它放在布局按钮上

android:focusable="false"
android:focusableInTouchMode="false"