Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final ListView l=(ListView)findViewById(R.id.listView1);
- ListAdapter k=new SimpleAdapter(this,val1,R.layout.mytask,new String[]{"TaskId","heading","status"},new int[]{R.id.View1,R.id.View2,R.id.ViewStatus});
- Button b=(Button)findViewById(R.id.mytask);
- l.setAdapter(k);
- <?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"
- android:orientation="vertical"
- >
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_marginTop="18dp"
- android:text="Task Name:"
- android:textSize="15dp"
- android:textStyle="bold" />
- <TextView
- android:id="@+id/View1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:text="TextView"
- android:textSize="15dp"
- android:textStyle="bold"
- android:visibility="invisible" />
- <TextView
- android:id="@+id/View2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/textView1"
- android:layout_alignBottom="@+id/textView1"
- android:layout_marginLeft="31dp"
- android:layout_toRightOf="@+id/textView1"
- android:text="TextView"
- android:textSize="15dp"
- android:textStyle="bold"
- android:visibility="visible" />
- <TextView
- android:id="@+id/ViewStatus"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/View2"
- android:layout_alignBottom="@+id/View2"
- android:layout_alignParentRight="true"
- android:text="Pending"
- android:textSize="15dp"
- android:textStyle="bold" />
- <TextView
- android:id="@+id/textView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/ViewStatus"
- android:layout_alignBottom="@+id/ViewStatus"
- android:layout_marginRight="14dp"
- android:layout_toLeftOf="@+id/ViewStatus"
- android:text="Status:"
- android:textSize="15dp"
- android:textStyle="bold" />
- <Button
- android:id="@+id/mytask"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/textView1"
- android:text="Button" />
- ListAdapter k=new SimpleAdapter(this,val1,R.layout.mytask,new String[]{"TaskId","heading","status"},new int[]{R.id.View1,R.id.View2,R.id.ViewStatus}) {
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- // get filled view from SimpleAdapter
- View itemView=super.getView(position, convertView, parent);
- // find our button there
- View myTaskButton=itemView.findViewById(R.id.mytask);
- // add an onClickListener
- myTaskButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // your button is pressed on this view
- }
- });
- return itemView;
- }
- };
- OnClickListener mTaskClickListener=new OnClickListener() {
- @Override
- public void onClick(View v) {
- // your button is pressed on this view, position is stored in tag.
- Integer positionPressed=(Integer)v.getTag();
- }
- };
- ListAdapter k=new SimpleAdapter(this,val1,R.layout.mytask,new String[]{"TaskId","heading","status"},new int[]{R.id.View1,R.id.View2,R.id.ViewStatus}) {
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- // get filled view from SimpleAdapter
- View itemView=super.getView(position, convertView, parent);
- // find our button there
- View myTaskButton=itemView.findViewById(R.id.mytask);
- // add an onClickListener, but this time is alredy created and the same for all
- myTaskButton.setOnClickListener(mTaskClickListener);
- myTaskButton.setTag(position); // so we know which tag was pressed
- return itemView;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement