I have get the data from local DB and display it in a ListView and I had a custom row with button
main.xml will contain ListView only
custom-row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
style="#color/background_gradient_start"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:alpha="0.6"
android:background="#color/background_gradient_start"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="177dp"
android:layout_height="75dp"
android:layout_weight="5" >
<TextView
android:id="#+id/textViewFlightNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textViewCodes"
android:layout_alignBottom="#+id/textViewCodes"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/textViewCodes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="18dp"
android:background="#color/transparent"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="16dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="142dp"
android:layout_height="match_parent"
android:layout_weight="5">
<Button
android:id="#+id/btn_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="1"
android:background="#3b3974"
android:focusable="false"
android:focusableInTouchMode="false"
android:minWidth="90dp"
android:text="Share"
android:textColor="#f1ecef" />
</RelativeLayout>
</LinearLayout>
Activity
so under on Create
String [] fromFiledName =new String[]{db.KEY_CODE};
int[] toViewIDs=new int[]{R.id.textViewCodes};
SimpleCursorAdapter myCurAdapter=new SimpleCursorAdapter(
this, //context
R.layout.listview_row_codes,
cursor,
fromFiledName,
toViewIDs
);
// set addapter to list view
ListView mylistPRN=(ListView) findViewById(R.id.codeslist);
mylistPRN.setAdapter(myCurAdapter);
mylistPRN.setAdapter(myCurAdapter);
mylistPRN.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//Intent intent2 = new Intent(this, PromoCodeActivity2.class);
Intent sendIntent = new Intent();
//intent.putExtra(PromoCodeActivity.requestString, httpRequestString);
//getItemAtPosition(position);
Cursor c = (Cursor) parent.getAdapter().getItem(position);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "share code "+c.getString(c.getColumnIndex("code")));
startActivity(Intent.createChooser(share, "Share Text"));
//startActivity(intentD);
}
});
The code is working and when I click on the list view item it open for sharing but I need it to open when the button is clicked as currently I tried to link the button but I couldn't. Any help
here is what you can do add following two lines to your buttons xml
android:focusable="false"
android:focusableInTouchMode="false"
Then inside adapter getView method attach onclickListener to this button and you are done. Currently there is no listener attached to button in row.
you don't need to use onItemClickListner as you are not clicking on the list Items, rather you have to set the onClickListner on buttons in your getview method
something like this this
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.imagelistlayout, null, true);
Button yourBtn = (Button)rowView.findViewById(R.id.your_btn_id);
yourBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
//Do your work here
}
});
return rowView;
}
Also set following properties on your button
android:focusable="false"
android:focusableInTouchMode="false"
Related
I'am trying to click a button on my list view to update that row first of all I tried to click on the item in the list view to show toast.
I did setOnItemClickListener of the ListView
public class Medlistview extends Activity{
DB db = new DB(this);
ImageButton updateimagebutton = (ImageButton)findViewById(R.id.editbuttonimage);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.medlistview);
populatemedlistview();
}
public void populatemedlistview(){
Cursor cursor = db.getMEDINF();
String[] medinfo = new String[]{
DB.col1,DB.col2,DB.col3,DB.col4,DB.rowID
};
int[] mappingmed = new int[]{
R.id.MEDid,R.id.MedName,R.id.Medpurpose,R.id.medNotaplet,R.id.ROWID
};
SimpleCursorAdapter medcursoradapter = new SimpleCursorAdapter(this,R.layout.medlistviewxml,cursor,medinfo,mappingmed);
ListView medlistview = (ListView)findViewById(R.id.listViewmed);
medlistview.setAdapter(medcursoradapter);
medlistview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(Medlistview.this,"clicked",Toast.LENGTH_LONG).show();
}
});
}
}
I made sure that my list view is clickable and focusable but still not working
One more thing I already define image button on layout item not on ListVew layout every time I run the app, is crashing and showing that null reference message in the log-cat do I need to define the button also on the ListView layout.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
My xml layout file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<ListView
android:layout_width="match_parent"
android:layout_height="282dp"
android:id="#+id/listViewmed"
android:layout_weight="0.40"
android:background="#c7c0c0"
android:clickable="true"
android:focusable="true" />
</LinearLayout>
Here is my list item xml layout file.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/MEDid"
android:layout_marginTop="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/MedName"
android:layout_below="#+id/MEDid"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/Medpurpose"
android:layout_below="#+id/MedName"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/medNotaplet"
android:layout_below="#+id/Medpurpose"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editbuttonimage"
android:layout_above="#+id/Medpurpose"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="#drawable/editicon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/ROWID"
android:layout_alignBottom="#+id/medNotaplet"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Thanks in Advance.
Implement View.OnClickListener() to your ImageButton in getView() method in your adapter, not in Medlistview activity. And use callback or eventBus to work with click action in your activity.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.recycler_view_item, parent, false);
holder.tvName = (TextView) convertView.findViewById(R.id.tvName);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvName.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Button was clicked
}
});
return convertView;
}
Set
android:focusable="false"
android:focusableInTouchMode="false"
for all UIs controls in your custom layout file.
use android:descendantFocusability="blocksDescendants" inside listview,
check out this answere: can't click on listview row with imagebutton
Set the parent layout of the item
android:descendantFocusability="blocksDescendants"
and set
android:clickable="false"
android:focusable="false">
on all your widgets.
As the subject suggests, setOnItemClickListener doesn't work when setOnLongClickListener is being used, the layout I'm using in the base adapter is below,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:paddingBottom="20dp"
android:paddingTop="5dp">
<com.mikhaellopez.circularimageview.CircularImageView
android:id="#+id/image1"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:focusable="false"
app:border_color="#EEEEEE"
app:border_width="4dp"/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/contacts_grid_image"
android:layout_centerHorizontal="true"
android:focusable="false"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="11dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/name"
android:layout_centerHorizontal="true"
android:focusable="false"
android:text="Mobile number"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="9dp"/>
</RelativeLayout>
and I'm using this,
image.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
ClipData.Item item = new ClipData.Item((CharSequence) v.getTag());
String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
ClipData dragData = new ClipData("test", mimeTypes, item);
MyDragShadowBuilder myShadow = new MyDragShadowBuilder(holder.image);
if (groups.size() > holder.position) {
v.startDrag(dragData, myShadow, null, 0);
return true;
}
});
and this,
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Log.i(TAG, "clicked");
}
});
Now when I tap on the image the item click doesn't work, but when i click on the text views it works, what am i doing wrong?
Also note that when I remove the image.setOnLongClickListener() the whole gridview item becomes clickable again.
This should be the expected behaviour for GridView, because the child view is clickable, even though it is only handling the OnLongClick only.
As a workaround, you can
setOnClickListener for ImageView to perform the same action as you would in setOnItemClickListener
consider using setOnItemLongClickListener, but this would affect the whole RelativeLayout
use onTouchListener, but this would requires more works
i am trying to make list view with clickable items, and every list_item must consist 2 clickable buttons.
But if i add buttons to item layout, iten click listener stops to work...
here is my item_layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<com.pkmmte.view.CircularImageView
android:id="#+id/friends_new_photo_circularImageView"
android:layout_gravity="center"
android:layout_width="#dimen/user_friends_width"
android:layout_height="#dimen/user_friends_height"
android:src="#mipmap/ic_launcher"
app:border="true"
app:border_color="#EEEEEE"
app:border_width="2dp"
app:shadow="true"/>
<ImageView
android:id="#+id/friends_new_online_status_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/online_status"
android:layout_alignBottom="#+id/friends_new_photo_circularImageView"
android:layout_alignRight="#+id/friends_new_photo_circularImageView"
android:layout_marginRight="8dp"
android:layout_marginBottom="5dp"/>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:id="#+id/friends_new_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"/>
<ImageView
android:id="#+id/friends_new_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="#drawable/stars"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="35dp"
android:onClick="true"
android:text="Add"/>
<Button
android:layout_width="wrap_content"
android:layout_height="35dp"
android:onClick="true"
android:text="Dismiss"/>
</LinearLayout>
</LinearLayout>
here is fragment layout (with listView):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview_friends"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/ListViewStyle"/>
</LinearLayout>
and here is my fragment with onCreateView and onItemClickListener:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_friends_listview, container, false);
ButterKnife.inject(this, rootView);
String[] mNames = {
"Example 1",
"Example 2"
};
mFriendsAdapter = new FriendsAdapter(getActivity(), null, 0);
List<String> mList = new ArrayList<>(Arrays.asList(mNames));
ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(
getActivity(),
R.layout.list_item_friends_new,
R.id.friends_new_name,
mList
);
mListView.setOnItemClickListener(this);
mListView.setAdapter(mAdapter);
return rootView;
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
FriendsFragment.openCurrentUser(getActivity());
}
So here is the question:
is it possible to make clickable listItems with clickable buttons?
and if its true, than how to do it? if it false - maybe you have some other solution?
I just found solution from here..but by deep clicking...
If any row item of list contains focusable or clickable view then OnItemClickListener won't work.
The row item must have a param like android:descendantFocusability="blocksDescendants".
here you can see example, how your list item should look like
row_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >
// your other widgets here
</LinearLayout>
or add these two lines for the inner views
android:focusable="false"
android:focusableInTouchMode="false"
remove onclick attribute like bellow in your code...
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="35dp"
android:onClick="true"//remove this
android:text="Add"/>
<Button
android:layout_width="wrap_content"
android:layout_height="35dp"
android:onClick="true" //remove this
android:text="Dismiss"/>
</LinearLayout>
and write your adapter as
ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(
getActivity(),
R.layout.list_item_friends_new,
R.id.friends_new_name,
mList
){
View.OnClickListener listener = new View.OnClickListener() {
#Override
public void onClick(View v) {
//your action on button click
}
};
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
Button button = (Button) view.findViewById(R.id.yourButtonID);
button.setOnClickListener(listener);
return view;
}
};
I checked all the previous questions regarding this issue , but none of them are helpfull to me .
My listview is not responding , i tried changing this
list.setOnItemClickListener(new ContactsListItemClickListener(this));
to
list.setOnItemClickListener(this);
by making my PrioritiseContacts activity just imeplement OnItemClickListener , but then too its not working .
The activity is successfully running , but i am unable to listen for listclick events.
How to correct this?
Here is my class :
public class PrioritiseContacts extends Activity implements OnClickListener {
private ListView list;
// list of contacts with name
private List<Contacts> contactsList;
private Controller controll;
private ContactListAdapters adapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_contacts);
controll = new Controller();
contactsList = controll.fetchContacts(this);
// call the adapter to set the list view layout
adapter = new ContactListAdapters(contactsList, this);
list = (ListView) findViewById(R.id.lv_contacts);
// set the adapter to list
list.setAdapter(adapter);
list.setOnItemClickListener(new ContactsListItemClickListener(this));
// inflate the list of contact
}
#Override
public void onClick(View arg0) {
Toast.makeText(this, "clicked", 1000).show();
}
class ContactsListItemClickListener implements OnItemClickListener {
private Context c;
public ContactsListItemClickListener(
PrioritiseContacts prioritiseContacts) {
this.c = prioritiseContacts;
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Toast.makeText(c, "Clicked", 1500).show();
System.out.print("clicked");
}
}
}
My select_contacts xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical">
<TextView
android:id="#+id/tv_select_contacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Choose Contacts"
android:textColor="#fdfdfd"
android:textSize="30dip"
android:gravity="center" >
</TextView>
<ListView
android:id="#+id/lv_contacts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:cacheColorHint="#00000000"
android:clickable="true"
android:focusable="true"
android:divider="#android:color/transparent"
android:dividerHeight="10.0sp"
android:scrollbars="none" >
</ListView>
</LinearLayout>
And this is my adapter's getview() :
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
// layout infklater to inflate the post list view
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
view = inflater.inflate(R.layout.contacts_list_view, null);
}
Contacts c = contactList.get(position);
// set text views in contact lists
// Typeface custom_font =
// Typeface.createFromAsset(context.getAssets(),"fonts/calibril.ttf");
TextView name = (TextView) view.findViewById(R.id.tv_contact_name);
// date.setTypeface(custom_font);
name.setText(c.getName());
TextView number = (TextView) view.findViewById(R.id.tv_number);
// title.setTypeface(custom_font);
number.setText(c.getPhone());
ImageView contact_image = (ImageView) view.findViewById(R.id.iv_single_contact);
// hut.setTypeface(custom_font);
if(c.getContactImage() != null)
contact_image.setImageBitmap(c.getContactImage());
else
contact_image.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_contact_picture_2));
return view;
}
My contacts_list_view xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_post_list"
android:layout_width="match_parent"
android:layout_height="50dip"
android:background="#000000"
android:gravity="left"
android:orientation="horizontal"
android:paddingBottom="2dp"
android:paddingTop="2dp" >
<ImageView
android:id="#+id/iv_single_contact"
android:layout_width="70dp"
android:layout_height="fill_parent"
android:layout_weight="0.05"
android:padding="2dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.87"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_contact_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="left"
android:paddingLeft="2dp"
android:text="Contact Name"
android:textColor="#fdfbfb"
android:textStyle="bold" />
<View style="#style/Divider" />
<TextView
android:id="#+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-thin"
android:gravity="left"
android:text="this is number"
android:textColor="#fdfbfb"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
<CheckBox
android:id="#+id/cb_contact"
android:layout_width="70dp"
android:layout_height="fill_parent"
android:layout_weight="0.05"
android:padding="2dp" />
</LinearLayout>
If any row item of list contains focusable or clickable view then OnItemClickListener won't work such as for checkbox or button etc in the row item.There are two solution:
1. row item must be having param like android:descendantFocusability="blocksDescendants"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >
// your other widgets here
</LinearLayout>
2. Set given two attributes to false
like
android:focusable="false"
android:focusableInTouchMode="false"
For example if there is any checkbox or button or image in the row item then
<CheckBox
android:id="#+id/fav_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
I am having a issue.
listview position 1
button1
listview position 2
button2
This is my designof listview . My adapter is as follow
adapter = new SimpleCursorAdapter(this, R.layout.appareal_listview_text ,cursor, new String[]{"Key_ProductName","Key_SellingPrice"} , new int[] {R.id.title_info_txt_v,R.id.description_info_txt_v});
Now i am giving my xml file appareal_listview_text.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="#drawable/layout1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/title_info_txt_v"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/description_info_txt_v"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:layout_marginTop="4dip"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold" />
<Button
android:id="#+id/btnBuyNow_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="15dp"
android:background="#drawable/buynow"
android:clickable="true"
android:onClick="buynowClick" />
</LinearLayout>
Now my porblem is that define my button in xml which is call by adapter and button is define only i just once in xml , and i want to perform different task on each click of each position of listview.For that i used
#Override
public void onListItemClick(ListView parent, View view, int position,
long id) {
Intent intent = new Intent(this, asasdad.class);
Cursor cursor = (Cursor) adapter.getItem(position);
intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
startActivity(intent);
System.out.println("list is click");
}
and as well as i can not use this
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// When clicked, show a toast with the TextView text
}
});
So how i will recognize which list button position is clicked to perform different task.
You should use following code.
button.setTag("position");
When button clicked,
String strPos = view.getTag();
Here you will get position of button.