vendredi 22 mai 2015

android: Not able to perform click event on TextView of custom layout in action bar

I am using different layout and showing into action bar. I want to perform event on click of textview of custom layout in action bar.

Here is my CustomLayout.xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@drawable/splashscreen_background">


                 <TextView 
                    android:id="@+id/text1"
                    android:layout_width="?attr/actionBarSize"
                    android:layout_height="match_parent"
                    android:textColor="#ff0000"
                    android:textSize="10sp"
                    android:textStyle="bold"
                    android:background="#034552"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:gravity="center"
                    android:minHeight="?android:attr/listPreferredItemHeight"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp"/>



                  <TextView 
                    android:id="@+id/text2"
                    android:layout_width="?attr/actionBarSize"
                    android:layout_height="match_parent"
                    android:textColor="#ff0000"
                    android:textSize="10sp"
                    android:textStyle="bold"
                    android:background="#034552"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:gravity="center"
                    android:minHeight="?android:attr/listPreferredItemHeight"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp"/>
</RelativeLayout>

And here I am trying to perform click event:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
        case R.id.text2:

            String link = JsonPhp.getInstance().getConfig().getmailboxURL()+"&username="+PreferenceHelper.get(PreferenceKeys.LoginKeys.LOGIN_NAME)+"&password="+PreferenceHelper.get(PreferenceKeys.LoginKeys.LOGIN_PASSWORD);
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
            startActivity(browserIntent);
            break;
        default:
            break;
        }
        return super.onOptionsItemSelected(item);
    }

Can anyone tell me what is the issue in my code.

Thanx.

Aucun commentaire:

Enregistrer un commentaire