Search code examples
androidtextviewandroid-relativelayoutcrash-reportsandroid-logcat

Click more than 3 times TextView, App gets crashed


I have 2 TextViews inside RelativeLayout. I have put clickable=true to my RelativeLayout so that when clicked RelativeLayout, both TextViews are highlighted. I have not set an Intent to my RelativeLayout. When I click one time, it is not crashing but the problem is, When I immediately click more than 3 times RelativeLayout it is crashing. In LogCat it is written: E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering Anybody who has faced such problem and fixed?? My XML file:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="127dp"
    android:background="#EEEEEE"
    android:clickable="true">

    <TextView
        android:id="@+id/txt_ne_ne"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="70dp"
        android:layout_marginStart="70dp"
        android:text="@string/qayerdan"
        android:textSize="12sp"
        android:layout_marginTop="10dp"
        android:textColor="@color/light_dark"/>
    <TextView
        android:id="@+id/txt_qayerdan_tanlash"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/tanlash"
        android:clickable="true"
        android:textColor="@color/black"
        android:layout_below="@+id/txt_ne_ne"
        android:layout_marginLeft="70dp"
        android:layout_marginStart="70dp"
        android:layout_marginTop="1dp"
        android:textSize="19sp" />
    <TextView
        android:id="@+id/txt_ne_ne2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="70dp"
        android:layout_marginStart="70dp"
        android:text="@string/qayerga"
        android:clickable="true"
        android:onClick="onCLick"
        android:textSize="12sp"
        android:layout_below="@id/txt_ne_ne"
        android:layout_marginTop="40dp"
        android:textColor="@color/light_dark"/>
    <TextView
        android:id="@+id/txt_qayerdan_tanlash2"
        android:clickable="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/tanlash1"
        android:textColor="@color/black"
        android:layout_below="@+id/txt_ne_ne2"
        android:layout_marginLeft="70dp"
        android:layout_marginStart="70dp"
        android:layout_marginTop="1dp"
        android:textSize="19sp" />

JAVA CODE:

    public class DelHome extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_del_h);


        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.post(new Runnable() {
            @Override
            public void run() {
                Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.menu, null);
                toolbar.setNavigationIcon(d);
            }
        });
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {

        int id = item.getItemId();

        if (id == R.id.nav_buyurt_yar) {

        } else if (id == R.id.nav_bosh_sahifa) {

        } else if (id == R.id.nav_call_centre) {

        } else if (id == R.id.nav_biz_haqimizda) {

        } else if (id == R.id.nav_foyd_shartlar) {

        } else if (id == R.id.nav_chiqish) {
            System.exit(0);
        }
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

Solution

  • Have you tried to set your RelativeLayout's background ? With something like this :

    With creating background_ripple.xml in drawable resources :

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true">
            <shape
                xmlns:android="http://schemas.android.com/apk/res/android">
                <solid android:color="@color/grey_light"/>
            </shape>
        </item>
        <item android:state_pressed="false">
            <shape
                xmlns:android="http://schemas.android.com/apk/res/android">
                <solid android:color="@color/white"/>
            </shape>
        </item>
    </selector>
    

    and settup it in your RelativeLayout

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="127dp"
        android:background="@drawable/background_ripple"
        android:clickable="true">
    
    </RelativeLayout>
    

    Edit : With something like this, Android may render a ripple effect

    I hope this will help you