开发者

android 2.3: page elements unclickable

Hello everybody I am pretty new at Android programming (2 months), so I hope you'll forgive my silly question, which has made me crazy for hours. I have developed an application having as a first page the following login form:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:scrollbars="vertical" android:scrollbarStyle="insideOverlay" android:layout_height="fill_parent" android:scrollbarAlwaysDrawVerticalTrack="true" android:gravity="top" android:id="@+id/LinearLayoutConnect" android:paddingTop="0px" android:paddingLeft="20px" android:paddingRight="10px" android:paddingBottom="20px">
    <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbarSize="10px" android:scrollbarStyle="insideOverlay" android:addStatesFromChildren="true" android:id="@+id/ScrollView03">
        <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/LinearLayout02">
            <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/connect" android:paddingTop="25px">
                <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal">
                    <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.envCode" android:id="@+id/label_env" android:textColor="#fff" android:layout_weight="33"></TextView>
                    <EditText android:layout_width="0dip" android:layout_height="wrap_content" android:id="@+id/env" android:layout_weight="67"></EditText> 
                </LinearLayout>

                <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:paddingTop="15px">
                    <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.email" android:id="@+id/label_login" android:textColor="#fff" android:layout_weight="33"></TextView>
                    <EditText android:layout_width="0dip" android:layout_height="wrap_content" android:id="@+id/login" android:layout_weight="67"></EditText>
                </LinearLayout>

                <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:paddingTop="15px">
                    <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.password" android:id="@+id/label_password" android:textColor="#fff" android:layout_weight="33"></TextView>
                    <EditText android:layout_width="0dip" android:layout_height="wrap_content" android:id="@+id/password" android:password="true" android:layout_weight="67"></EditText>
                </LinearLayout>

                <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:enabled="true" android:text="@string/connect.remember" android:id="@+id/che_user_save" android:layout_gravity="center" android:paddingTop="20px"></CheckBox>

                <TableLayout android:id="@+id/TableLayoutconnect" android:layout_height="wrap_content" android:visibility="visible" android:layout_width="fill_parent" android:paddingTop="20px">
                    <TableRow android:id="@+id/TableRowconnect01" android:layout_height="wrap_content" android:layout_width="fill_parent">
                        <Button android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/connect.connect" android:id="@+id/auth_button_connect" android:layout_weight="52"></Button>
                        <Button android:layout_width="0dip" android:layout_height="wrap_content" android:text="@string/global.reset" android:id="@+id/auth_button_reset" android:layout_weight="48"></Button>
                    </TableRow>
                </TableLayout>

                <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/connect.link" android:width="266sp" android:gravity="center" android:layout_marginTop开发者_如何学C="20sp" android:padding="4sp" android:background="#fe0000" android:textColor="#ffffff" android:id="@+id/PromoBar" ></TextView>
            </LinearLayout>

            <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/disconnect">
                <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/global.disconnect" android:id="@+id/auth_button_disconnect" android:layout_weight="60"></Button>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

This is the related Java code:

env = (EditText) findViewById(R.id.env);
txt_login = (EditText) findViewById(R.id.login);
txt_password = (EditText) findViewById(R.id.password);

but_connect = (Button) findViewById(R.id.auth_button_connect);
but_connect.setOnClickListener(new OnClickListener(){
    public void onClick(View v) {
        XMLRPC_connect();
    }
});

but_reset = (Button) findViewById(R.id.auth_button_reset);
but_reset.setOnClickListener(new OnClickListener(){
    public void onClick(View v) {
    try {
            ClearSettings(getBaseContext(),filename_settings);
            env.setText("");
                txt_login.setText("");
                txt_password.setText("");
        } catch(Exception e) {}
    }
});

The question is: In the previous versions of Android (up to 2.2) all the buttons and EditText fields are perfectly clickable and editable.

On Android 2.3 (using an emulator under Eclipse - don't have a real device) the screen is totally insensitive to touch or click: no element on it can be selected and highlighted, it's possible to do so only using the trackball or the keyboard, resulting to be pretty annoying. The screen itself is not scrollable.

I tried to force all TextEdit fields and Buttons editable, focusable or clickable, I tried to update Eclipse ADT, I tried to compile the project with Android 2.3 libraries,... no result. Whatever element I click on, its onClick function is never triggered... I've really run out of solutions! Thanks for your help!


I have three advices:

  1. I think you can get rid of the LinearLayout with the id connect and disconnect they are both vertical and embedded in a vertical LinearLayout with id LinearLayout02. The result should be the same.
  2. Override the onTouchEvent in the activity and check if this is called when you touch the screen. From there on go deeper in the layout step by step.
  3. Try to remove one view/layout at a time. Maybe you find the reason that way....
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜