Set Up Android View Clickable
I set up splash activity which start another activity after few second. Anyway I wanted to add one more capability: to start the second activity not only after 5 second but after a
Solution 1:
Make the LinearLayout clickable by setting layout attribute android:clickable="true"
, android:focusable="true"
and android:focusableInTouchMode="true"
from xml or setClickable(true)
from code. set onClickListener as
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:background="@drawable/splash2"/>
and in code part:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
((LinearLayout)findViewById(R.id.splash)).setOnClickListener(this);
/// YOUR CODE HERE
Solution 2:
Solution 3:
XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="@drawable/splash2"android:id="@+id/splash"android:clickable="true" >
</LinearLayout>
setContentView(R.layout.name);
Linearlayout v = (LinearLayout)findViewById(R.layout.splash);
v.setOnClickListener(this);
Solution 4:
You cannot use the findViewById(int id)
before setContentView()
a layout inflater would be of help also set android:clickable="true"
, android:focusable="true"
and android:focusableInTouchMode="true"
on the layout.
Post a Comment for "Set Up Android View Clickable"