English 中文(简体)
在调试人进行名单调查时,有一个问题,有纽芬兰语点击听众。
原标题:Inside an Adapter for listview, there s an issue with button click listener
public class ImageAndTextListAdapter extends ArrayAdapter<ImageAndText> {

//   new method
    private ListView listView;
    private AsyncImageLoader asyncImageLoader;
     private ImageAndText imageAndText;

//constructor
public ImageAndTextListAdapter(Activity activity, List<ImageAndText> imageAndTexts) {
    super(activity, 0, imageAndTexts);


    asyncImageLoader = new AsyncImageLoader();
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Activity activity = (Activity) getContext();


    ////////////////////////////////////////////////////////////////////////////////////////////////
    // Load the image and set it on the ImageView


    //new method
    // Inflate the views from XML
    View rowView = convertView;
    ViewCache viewCache;

    if (rowView == null) {
        LayoutInflater inflater = activity.getLayoutInflater();
        rowView = inflater.inflate(R.layout.image_and_text_row, null);
        viewCache = new ViewCache(rowView);
        rowView.setTag(viewCache);
    } else {
        viewCache = (ViewCache) rowView.getTag();
    }
    imageAndText = getItem(position);

    Button btn2=(Button) findViewById(R.id.button1);

      btn2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

                     //...........
               }
      });

该校对《名单》进行校正,采用图像_和_text_row.xml,这些图像代表了名单上的浏览数据。 节目在我点击听众时坠毁。 如果听众被删除,那么该方案就会被罚款。

the question is why the adapter cannot have a button click listener inside the code?

最佳回答

光是在黑暗中射出的:但是,您的界线Button btn2=(Button)找到了“ById(R.id.button1)”号;是指适应者身处的“清单”或“名单”。 因此,R.id.button1 不存在......

您:Button btn2=(Button)rowView.findViewById(R.id.button1)); 这可能是你的问题(看不到你的记录,即)。 <编码>findViewById(>>发现儿童。 最初的发言将着眼于活动或观点的儿童。 这一新声明将发现该意见的子孙。

当然,这是一个假设,因为你没有完全描述申请或问题,我必须根据我们掌握的信息,即每行都有一个子。

希望这一帮助,

Fuzzical Carloic

www.un.org/Depts/DGACM/index_spanish.htm P.S. 如果缺乏相关信息,希望你们会得到像这种错误的答复。 良好的指南是:1)正在发生什么? (2) 你们预计会发生什么情况? 3) 贵重资源如何显示? (4) 我们需要知道哪些补充研究或概念? 这些问题带来了更长时间的问题,但肯定会更加有效,因此答案也是这样。

问题回答

What you should do is add the onClick to your xml file where the button is. Also make sure your button is inside the same layout you are inflating.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签