0

This is the list view and I want to click the every value of the cell...

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

And want to get the values of the field...

I have a Listview where I want to get the values of individual item of that listview from my 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 .....

        }

}

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

Header.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 ");
//
//  }

}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
NRahman
  • 2,717
  • 5
  • 24
  • 29
  • Post your MyListAdapter so that we can come to know what are view your used in adapter layout – Srikanth Jul 03 '13 at 12:04
  • Use base-adapter to implement this thing easily. – Yugesh Jul 03 '13 at 12:32
  • possible duplicate of [Android: ListView elements with multiple clickable buttons](http://stackoverflow.com/questions/1709166/android-listview-elements-with-multiple-clickable-buttons) – Jim G. Apr 06 '14 at 14:09

1 Answers1

0

once you setup your custom ListView you need to refrence each element with an id. Then you can detect the position of the button clicked. Hope this help you!

  • I have been able to make them clickable from the adapter class but i want to make them clickable from this main activity....how to do that ???? – NRahman Jul 03 '13 at 12:06
  • check this link : http://stackoverflow.com/questions/1709166/android-listview-elements-with-multiple-clickable-buttons if it helps you don't forget to rate my answer up! :) –  Jul 03 '13 at 12:10
  • @NRahman : Sorry you can't. If you wan't to fire some action in main activity at click and there is no other alternative, you have to follow a slightly longer path. create a custom View, add all the required views in that and then write one custom-listener for that. you can have some flags inside the custom View, change the values of those flags by button click and listen to change the values of those flags in main activity. – sachin garg Jul 03 '13 at 12:32