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
0 comments:
Post a Comment