0

这是列表视图,我想单击单元格的每个值...

_________________________________
               |                 |
         1     |                 |
               |           2     |
_______________|_________________|
               |                 |
               |             4   |
       3       |                 |
_______________|_________________|

并想获取该字段的值...

我有一个列表视图,我想从我的 MainActivity 中获取该列表视图的单个项目的值...

    public class MainActivity extends Activity implements OnItemClickListener {
         ListView mylist;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            LayoutInflater i = LayoutInflater.from(this);

            ListView mylist=(ListView)findViewById(R.id.listexample);

            List<Item> items = new ArrayList<Item>();
            items.add(new Header(i, "Group","See More",R.drawable.ic_launcher));
            items.add(new EventItem(i, R.drawable.demoimage , R.drawable.demoimage ,R.drawable.demoimage ,R.drawable.demoimage ));




            MyListAdapter adapter = new MyListAdapter(this, items);
            mylist.setAdapter(adapter);
            mylist.setOnItemClickListener(this);
        }

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

    //What will the Value here .....

        }

}

..................................................

头文件.java

package com.antew.listexample;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
import com.antew.listexample.MyListAdapter.RowType;

public class Header implements Item, OnClickListener {
    private final String catagory;
    private final String see_more;
    private final int image;
    private final LayoutInflater inflater;

    public Header(LayoutInflater inflater, String catagory, String see_more,
            int image) {
        this.catagory = catagory;
        this.see_more = see_more;
        this.image = image;
        this.inflater = inflater;
    }

    @Override
    public int getViewType() {
        return RowType.HEADER_ITEM.ordinal();
    }

    @Override
    public View getView(View convertView) {
        if (convertView == null) {

            convertView = (View) inflater.inflate(R.layout.header, null);
        }

        TextView cat = (TextView) convertView
                .findViewById(R.id.header_catagory);
        cat.setText(catagory);

    //  cat.setOnClickListener(Header.this);

        TextView s_m = (TextView) convertView.findViewById(R.id.header_seemore);
        s_m.setText(see_more);

        ImageButton imb = (ImageButton) convertView
                .findViewById(R.id.header_imageButton1);

        imb.setBackgroundResource(image);
        return convertView;
    }

//  @Override
//  public void onClick(View v) {
//      // TODO Auto-generated method stub
//
//      Log.d("*****************CLCIK", v.toString() + "CATAGORY CLICKED ");
//
//  }

}
4

1 回答 1

0

设置自定义 ListView 后,您需要使用 id 引用每个元素。然后您可以检测单击按钮的位置。希望这对你有帮助!

于 2013-07-03T12:04:41.490 回答