gpt4 book ai didi

android - 无法声明按钮,Eclipse 不断抛出错误

转载 作者:太空狗 更新时间:2023-10-29 16:21:07 27 4
gpt4 key购买 nike

我试图放置一个按钮,但我不知道为什么 Eclipse 一直向我抛出此错误“局部变量按钮可能尚未初始化”。我在 xml 文件“rssfeedadapter_layout”中添加了一个按钮。但是我不能在代码中调用它。我正在尝试这个:

RssReaderListAdapter.java

package com.rssfeed.adapter;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.rssfeed.R;
import com.rssfeed.helper.RssFeedStructure;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class RssReaderListAdapter extends ArrayAdapter<RssFeedStructure> {

List<RssFeedStructure> imageAndTexts1 =null;
public RssReaderListAdapter(Activity activity, List<RssFeedStructure> imageAndTexts) {
super(activity, 0, imageAndTexts);
imageAndTexts1 = imageAndTexts;

}


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

Activity activity = (Activity) getContext();
LayoutInflater inflater = activity.getLayoutInflater();


View rowView = inflater.inflate(R.layout.rssfeedadapter_layout, null);
TextView title = (TextView) rowView.findViewById(R.id.feed_text);
TextView description = (TextView) rowView.findViewById(R.id.feed_updatetime);
ImageButton button = (ImageButton) button.findViewById(R.id.button_web);//Eclipse keeps throwing error in this line
ImageView imageView = (ImageView) rowView.findViewById(R.id.feed_image);
ImageLoader imgLoader;
imgLoader = new ImageLoader(activity);
Log.d("rssfeed", "imageAndTexts1.get(position).getImgLink() :: " +imageAndTexts1.get(position).getImgLink() +" :: " +imageAndTexts1.get(position).getTitle());
title.setText(imageAndTexts1.get(position).getTitle());
description.setText(imageAndTexts1.get(position).getDescription());
if(imageAndTexts1.get(position).getImgLink() !=null){

String imageUrl= imageAndTexts1.get(position).getImgLink();
imgLoader.DisplayImage(imageUrl, imageView);

}

return rowView;

}

}

最佳答案

使用

ImageButton button = (ImageButton) rowView.findViewById(R.id.button_web);

代替

ImageButton button = (ImageButton) button.findViewById(R.id.button_web);

您需要使用 rowViewrssfeedadapter_layout 布局而不是按钮获取初始化按钮

关于android - 无法声明按钮,Eclipse 不断抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14565852/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com